【问题标题】:Using Spring Boot, QueryDSL, and Springfox Swagger together - Guava version mismatch一起使用 Spring Boot、QueryDSL 和 Springfox Swagger - Guava 版本不匹配
【发布时间】:2020-01-17 22:19:38
【问题描述】:

我正在尝试将 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(希望它仍然可以运行)?或者有没有其他方法可以解决这个问题?

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

【问题讨论】:

    标签: java spring spring-boot swagger querydsl


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-04
      相关资源
      最近更新 更多