尝试在Java Spring API中实现Swagger时出现错误消息

时间:2020-05-15 17:01:26

标签: java spring api maven swagger

在使用Spring制作的API中添加Swagger之后,运行时出现以下错误消息:

export const findDmaFromHierarchy = (hierarchy: [], value: string): any => {
  let found = undefined;
  hierarchy.some((dma: any) => {
    if (String(dma.value) === String(value)) {
      console.log("founded: ", dma);
      found = Object.assign({}, dma);
      return true;
    }

    if (dma.children) {
      let temp = findDmaFromHierarchy(dma.children, value);
      if (temp) {
          found = temp;
          return tru;
      }
    }
  });
  return found;
};

我的pom.xml文件:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-15 13:51:39.631 ERROR 13804 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory.<init>(UnwrappingRepositoryInvokerFactory.java:57)

The following method did not exist:

    'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(java.util.List)'

The method's class, org.springframework.plugin.core.PluginRegistry, is available from the following locations:

    jar:file:/home/gabriel/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/home/gabriel/.m2/repository/org/springframework/plugin/spring-plugin-core/1.2.0.RELEASE/spring-plugin-core-1.2.0.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry


Process finished with exit code 1

明智地编码,我认为一切都很好。我几乎可以确定,解决该问题的方法是使用Maven文件的依赖项。

我尝试了一些我在网上找到的解决方案,但是都没有用,如果有人可以与我分享一些有关此方面的知识,将不胜感激。

2 个答案:

答案 0 :(得分:1)

可以从POM文件中删除以下依赖项:

<dependency>
    <groupId>org.springframework.plugin</groupId>
    <artifactId>spring-plugin-core</artifactId>
    <version>1.2.0.RELEASE</version>
</dependency>

此依赖项已经是Swagger依赖项的可传递依赖项(编译范围)。 单独添加此依赖项会在运行时与spring-boot-starter-data-rest依赖项产生冲突。通过从POM文件中删除它,您可以允许Maven选择正确的版本(它将是最新版本,它将与Spring Boot兼容)。当前版本被强制为1.2.0.RELEASE,而Spring Boot可能需要2.0.0.RELEASE

Swagger仅需要POM文件中的以下依赖项:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

如果您的应用程序确实需要spring-plugin-core依赖性,则可以更改版本而不是删除它。然后将排除项添加到Swagger依赖项也将是正确的做法。

答案 1 :(得分:0)

因此,我找到了解决问题的方法,这全都涉及我在api中使用的软件版本之间的不兼容性。

我将春季版本更改为2.3.0,并且对pom文件添加了以下依赖性:

<dependency>
      <groupId>org.javassist</groupId>
      <artifactId>javassist</artifactId>
      <version>3.23.1-GA</version>
    </dependency>

信用: https://github.com/spring-projects/spring-boot/issues/14610