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

Using Spring Boot, QueryDSL, and Springfox Swagger together - Guava version mismatch

我正在尝试将 QueryDSL 用于 Spring 数据谓词解析,并尝试将 Swagger API 文档用于我的 Spring 引导服务。但是我 运行 遇到了问题。当我的应用程序启动时,我收到此错误消息:

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 库,所以我最终在我的库中得到了两个版本的库classpath 和 maven 似乎优先考虑 18.0。我该如何修复这种依赖不匹配?有什么办法可以强制 QueryDSL 尝试使用 Guava 20.0(希望它仍然可以运行)?或者可能有任何其他解决方法吗?

版本: Spring 引导版本:2.1.9.RELEASE 此版本 Spring Boot 使用 QueryDSL 版本:4.2.1 Springfox Swagger 版本:2.9.2

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

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

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