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

无法使用Spring Fox启动bean“documentationPluginsBootstrapper”Spring boot Swagger实现?

华谭三
2023-03-14

我在我的Spring启动应用程序中使用springfox-boot-starter依赖于昂首阔步的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>

为什么我会犯这样的错误,我什么都不懂。任何帮助都将不胜感激。提前谢谢。

共有1个答案

冯文彬
2023-03-14

我有一个类似的问题,并在这里找到了解决方案。基本上,您必须在文件application.properties中包含以下配置:

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

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

 类似资料: