【问题标题】:Failed to start bean 'documentationPluginsBootstrapper' Spring boot Swagger implementation using Spring Fox?无法使用 Spring Fox 启动 bean 'documentationPluginsBootstrapper' Spring boot Swagger 实现?
【发布时间】:2021-01-07 12:35:55
【问题描述】:

我在我的 Spring Boot 应用程序中使用 springfox-boot-starter 依赖于 swagger UI,但是当我尝试运行该应用程序时出现以下错误

    Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginFor(Ljava/lang/Object;)Ljava/util/Optional;
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:184)
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:157)
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:121)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:885)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)

我的配置文件:


 @Bean
 public Docket productApi() {
        
     return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.swagger.demo.controller"))
        .paths(regex("/student.*"))
        .build()
        .enableUrlTemplating(true)
        .produces(DEFAULT_PRODUCES_AND_CONSUMES)
        .consumes(DEFAULT_PRODUCES_AND_CONSUMES)
        .apiInfo(apiEndPointsInfo());
    }

private ApiInfo apiEndPointsInfo() {

    return new ApiInfoBuilder()
            .title("demo")
            .description("demo")
            .version("1.0")
            .build();
} 

下面是我正在使用的依赖项。 pom.xml 文件:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
    
<dependencies>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-boot-starter</artifactId>
      <version>3.0.0</version>
    </dependency>
</dependencies>

为什么我会遇到错误,我什么也没得到。任何帮助将不胜感激。提前致谢。

【问题讨论】:

标签: spring-boot swagger springfox


【解决方案1】:

我遇到了类似的问题并找到了解决方案here。 基本上你必须在文件application.properties 中包含以下配置:

spring.mvc.pathmatch.matching-strategy=ant-path-matcher

似乎 Spring Boot 2+ 将基于 PathPathern 的匹配器设置为默认值,而 Spring Fox 期望基于 Ant 的匹配器。 这个解决方案的问题是你不能使用 Spring Actuator,因为它使用基于 PathPattern 的 URL 匹配。在这种情况下,请检查此Spring Fox issue

【讨论】:

    猜你喜欢
    • 2019-09-29
    • 2021-12-30
    • 2022-07-19
    • 2017-06-02
    • 1970-01-01
    • 2017-06-18
    • 2021-12-31
    • 2021-04-25
    • 1970-01-01
    相关资源
    最近更新 更多