【问题标题】:Spring Data Rest module 2.1.3 and Swagger 2.9.2 causing problemSpring Data Rest 模块 2.1.3 和 Swagger 2.9.2 导致问题
【发布时间】:2019-03-21 16:32:49
【问题描述】:

我正在尝试使用 swagger-ui 调整 spring data rest 模块,我正在使用 SpringBoot 2.1.3.RELEASE 版本和 2.9.2 版本的 swagger 依赖项,其中包括 springfox-data-rest 、 springfox-swagger2、springfox-招摇-ui。

An attempt was made to call the method org.springframework.data.repository.support.Repositories.getRepositoryInformationFor(Ljava/lang/Class;)Lorg/springframework/data/repository/core/RepositoryInformation; but it does not exist. Its class, org.springframework.data.repository.support.Repositories, is available from the following locations:
    jar:file:/Users/batuhan.apaydin/.m2/repository/org/springframework/data/spring-data-commons/2.1.5.RELEASE/spring-data-commons-2.1.5.RELEASE.jar!/org/springframework/data/repository/support/Repositories.class
It was loaded from the following location:
    file:/Users/batuhan.apaydin/.m2/repository/org/springframework/data/spring-data-commons/2.1.5.RELEASE/spring-data-commons-2.1.5.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.support.Repositories

我也尝试添加

@Import({springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration.class})

但没有任何问题。

有人知道我为什么会收到这个错误吗?

【问题讨论】:

  • 请出示您的pom.xml-

标签: spring-boot spring-data-rest swagger-2.0


【解决方案1】:

我遇到了同样的问题,找到了以下解决方案:

使用 Swagger 3.0.0 的快照版本

<dependencies>
    ...
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-data-rest</artifactId>
        <version>3.0.0-SNAPSHOT</version>
    </dependency>
    ...
</dependencies>

<repositories>
    <repository>
        <id>JFrog</id>
        <name>JFrog Snapshot Repository</name>
        <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
    </repository>
</repositories>

然后使用@EnableSwagger2WebMvc 代替@EnableSwagger2:

@SpringBootApplication
@EnableSwagger2WebMvc
@Import(SpringDataRestConfiguration.class)
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

}

这里提到:https://github.com/springfox/springfox/issues/2345#issuecomment-493437424

【讨论】:

  • 看看这里的 cmets,也许你不知道。 meta.stackexchange.com/questions/214173/…有了这样的答案,你应该很快就会越过那个门槛。 (请理解,我不能赞成这个答案,我只能说它确实试图回答,但从技术上讲它是否正确和有帮助。不过祝你好运。)
猜你喜欢
  • 2016-02-01
  • 2021-12-31
  • 1970-01-01
  • 2012-09-25
  • 1970-01-01
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
  • 2020-10-18
相关资源
最近更新 更多