简体   繁体   English

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

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

I'm trying to use QueryDSL for Spring Data predicate resolution as well as Swagger API documentation for my Spring Boot service.我正在尝试将 QueryDSL 用于 Spring Data 谓词解析以及我的 Spring Boot 服务的 Swagger API 文档。 However I've run into a problem.但是我遇到了一个问题。 When my application starts, I get this error message:当我的应用程序启动时,我收到此错误消息:

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

I've discovered that this is happening because QueryDSL is dependent on Guava 18.0 library, but Springfox / Swagger is dependent on Guava 20.0 library, so I end up with both versions of the library on my classpath and maven seems to prioritize the 18.0 one.我发现发生这种情况是因为 QueryDSL 依赖于 Guava 18.0 库,但 Springfox / Swagger 依赖于 Guava 20.0 库,所以我最终在我的类路径上使用了两个版本的库,而 maven 似乎优先考虑 18.0 库。 How can I fix this dependency mismatch?如何修复此依赖项不匹配? Is there any way to force QueryDSL to try to use Guava 20.0 (in the hopes that it will still function)?有什么方法可以强制 QueryDSL 尝试使用 Guava 20.0(希望它仍然可以运行)? Or could there possibly be any other way around this?或者可能有其他方法解决这个问题?

Versions: Spring Boot version: 2.1.9.RELEASE This version of Spring Boot uses QueryDSL version: 4.2.1 Springfox Swagger version: 2.9.2版本:Spring Boot 版本: 2.1.9.RELEASE此版本的 Spring Boot 使用 QueryDSL 版本: 4.2.1 Springfox Swagger 版本: 2.9.2

If using Gradle, you can force the use of a specific library version.如果使用 Gradle,您可以强制使用特定的库版本。 In this case, you may use the following syntax -在这种情况下,您可以使用以下语法 -

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

I'm sure there's a similar solution if you use a different build tool.如果您使用不同的构建工具,我相信会有类似的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM