一起使用Spring Boot,QueryDSL和Springfox Swagger-Guava版本不匹配

问题描述 投票:1回答:1

我正在尝试将QueryDSL用于Spring Data谓词解析以及用于Spring Boot服务的Swagger API文档。但是我遇到了一个问题。当我的应用程序启动时,我收到以下错误消息:

java.lang.NoSuchMethodError: 'com.google.common.collect.FluentIterable com.google.common.collect.FluentIterable.concat(java.lang.Iterable, java.lang.Iterable)

An attempt was made to call a method that does not exist. The attempt was made from the following location:
 springfox.documentation.schema.DefaultModelDependencyProvider.dependentModels(DefaultModelDependencyProvider.java:79)

The following method did not exist:

    'com.google.common.collect.FluentIterable com.google.common.collect.FluentIterable.concat(java.lang.Iterable, java.lang.Iterable)'

The method's class, com.google.common.collect.FluentIterable, is available from the following locations:

    jar:file:/my_m2/com/google/guava/guava/18.0/guava-18.0.jar!/com/google/common/collect/FluentIterable.class

Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable

我发现发生这种情况是因为QueryDSL依赖于Guava 18.0库,但是Springfox / Swagger依赖于Guava 20.0库,所以我最终在类路径中使用了两个版本的库,而maven似乎优先考虑18.0版一。如何解决此依赖性不匹配?有什么方法可以强迫QueryDSL尝试使用Guava 20.0(希望它仍然可以运行)?还是可能有其他解决方法?

版本:春季启动版本:2.1.9.RELEASE此版本的Spring Boot使用QueryDSL版本:4.2.1Springfox Swagger版本:2.9.2

java spring spring-boot swagger querydsl
1个回答
1
投票

如果使用Gradle,则可以强制使用特定的库版本。在这种情况下,您可以使用以下语法-

configurations.all {
    resolutionStrategy.force "com.google.guava:guava:$guavaVersion"
}

如果您使用其他构建工具,我敢肯定会有类似的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.