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



我正在尝试使用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.1春狐招摇版:2.9.2

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

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

如果您使用不同的构建工具,我相信会有类似的解决方案。

最新更新