Spring Boot 试图调用不存在的方法,尝试是从以下位置进行的:

vq8itlhq  于 2023-03-08  发布在  Spring
关注(0)|答案(3)|浏览(181)

我正在处理Spring boot JPA Gridle project,当前Swagger正在运行,DTO运行时出错,模块之间好像有冲突。
当我安装swagger模块、继续使用swagger并安装DTO模块时,出现错误。以下模块产生错误:
compile 'org.springframework.boot:spring-boot-starter-hateoas'
错误如下。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-17 01:26:38.657 ERROR 4688 --- [           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:

    springfox.documentation.spring.web.plugins.DocumentationPluginsManager.createContextBuilder(DocumentationPluginsManager.java:152)

The following method did not exist:

    org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;

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

    jar:file:/Users/****/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/2.0.0.RELEASE/95fc8c13037630f4aba9c51141f535becec00fe6/spring-plugin-core-2.0.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/Users/****/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/2.0.0.RELEASE/95fc8c13037630f4aba9c51141f535becec00fe6/spring-plugin-core-2.0.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

我在搜索中尝试过的东西也是。

compile group: 'org.springframework.plugin', name: 'spring-plugin-core', version: '2.0.0.RELEASE'

compile group: 'io.springfox', name: 'springfox-data-rest', version: '2.9.2'

他们两个都没帮我。
有人和我有同样的问题吗?
有没有别的办法来解决这个问题?

cyej8jka

cyej8jka1#

问题是Swagger和Hateoas模块之间的冲突。多个搜索结果已经找到了解决方案。
解决方案是添加一个新模块并为其注册Bean

compile group: 'org.springframework.plugin', name: 'spring-plugin-core', version: '1.2.0.RELEASE'

** Swagger 配置.java**

public class SwaggerConfig {

    @Bean
    public LinkDiscoverers discoverers() {
        List<LinkDiscoverer> plugins = new ArrayList<>();
        plugins.add(new CollectionJsonLinkDiscoverer());
        return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
    }

}
7bsow1i6

7bsow1i62#

对我来说,问题是JPA和Hateoas依赖关系之间的冲突。
我的解决方案是删除JPA依赖项,因为我对使用Hateoas模块感兴趣。
变更内容:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>

对此:

<dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
    </dependency>
cgfeq70w

cgfeq70w3#

对我来说,这是Swagger和JPA之间的冲突,所以我不得不将SpringBoot从2. 1. 9-Release升级到2. 7. 5。

相关问题