当前位置: 首页 > 知识库问答 >
问题:

使用Spring Fox的Spring boot Swagger实现无法启动bean“Documentation PluginsBootstrapper”

殳经略
2023-03-14

在我的spring boot项目中,我使用Springfox jars实现了swagger,gradle依赖关系如下所示:

dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.1.3.RELEASE'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: '2.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.3.RELEASE'
implementation 'org.flywaydb:flyway-core'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.hsqldb:hsqldb'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'io.projectreactor:reactor-test'
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.1'
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.1'
    //compile group: 'io.springfox', name: 'springfox-data-rest', version: '2.9.1'
    // Unit testing dependencies
    // Set this dependency if you want to use Hamcrest matching

}
package com.myapp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select()
                .apis(RequestHandlerSelectors.basePackage("com.mypackage.rtp.controller"))
                .paths(PathSelectors.regex("/.*")).build().apiInfo(apiEndPointsInfo());
    }

    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder().title("Spring Boot REST API").description("Employee Management REST API")
                .license("Apache 2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html").version("1.0.0")
                .build();
    }

}
WARN  [main] org.springframework.context.support.AbstractApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;
***************************
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.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;

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

    jar:file:/C:/Users/vgoswami/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/1.2.0.RELEASE/f380e7760032e7d929184f8ad8a33716b75c0657/spring-plugin-core-1.2.0.RELEASE.jar!/org/springframework/plugin/core/PluginRegistry.class

It was loaded from the following location:

    file:/C:/Users/vgoswami/.gradle/caches/modules-2/files-2.1/org.springframework.plugin/spring-plugin-core/1.2.0.RELEASE/f380e7760032e7d929184f8ad8a33716b75c0657/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

共有1个答案

卫景明
2023-03-14

我也有同样的问题,在花了很长时间搞定spring-core、swagger等之后,我发现下面的依赖才是真正的罪魁祸首

spring-boot-starter-data-rest

只要把这个移开,你就完成了。

 类似资料:
  • 我正在尝试使用Open Jdk 15、Springboot 2.6.0和Springfox 3启动一个Springboot项目。我们正在开发一个项目,该项目将Netty替换为Web服务器,并使用Jetty,因为我们不需要非阻塞环境。 在代码中,我们主要依赖于Reactor API(Flux,Mono),因此我们不能删除org.springframework。启动:spring boot start

  • 我在我的Spring启动应用程序中使用springfox-boot-starter依赖于昂首阔步的UI,但当我尝试运行应用程序时,我得到以下错误 我的配置文件: 下面是我正在使用的依赖项。pom。xml文件: 为什么我会犯这样的错误,我什么都不懂。任何帮助都将不胜感激。提前谢谢。

  • 我按照这个教程https://spring framework . guru/spring-boot-restful-API-documentation-with-swagger-2/生成了一个swagger文档。它可以工作,但是当我试图在bean中添加一些验证时,我在文档中找不到信息: 带有验证注释的我的实体: 这里,https://github.com/springfox/springfox/

  • 我在我的应用程序中使用spring data rest。 我收到以下错误,当我在存储库中添加此方法时,应用程序无法启动:- 方法:- 错误:- 如何解决这个问题? 更新时间:- 所有依赖项的列表:-

  • 我正在尝试启动一个简单的spring应用程序 我有主管道。java文件就在这里: 这是pom。xml: 最后一个错误是: 据我所知我少了一颗豆子?然而,看起来好像我有罐子春豆。

  • Maven build成功了,但当我尝试运行它时失败了: 我有带 一切似乎都准备就绪。发生了什么? pom.xml 更新1 使用IntelliJ构建jar工件时也是如此。 更新2 好的,我设法运行了它,但现在我有: 更新3 通过添加到应用程序使其正常工作。爪哇: