10

I am using springfox-boot-starter dependency for swagger UI in my spring boot application but when I try to run the application I am getting below error

    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)

my config file:


 @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();
} 

Below is the dependency which I am using. pom.xml file:

<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>

Why I am getting above error I don't get anything. Any help would be highly appreciated. Thanks in advance.

Helen
  • 87,344
  • 17
  • 243
  • 314
Rajesh kumar
  • 126
  • 1
  • 1
  • 7
  • Does this answer your question? [Failed to start bean 'documentationPluginsBootstrapper' in spring data rest](https://stackoverflow.com/questions/40241843/failed-to-start-bean-documentationpluginsbootstrapper-in-spring-data-rest) – flaxel Sep 21 '20 at 14:05
  • Any update on this? Facing the same issue. Is any fix available? – Jignesh M. Khatri Nov 22 '21 at 16:09

2 Answers2

26

I had a similar issue and found the solution here. Basically you have to include in the file application.properties the following configuration:

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

As it seems Spring Boot 2+ set as default the PathPathern-based matcher, while Spring Fox expects the Ant-based matcher. The problem with this solution is that you cannot use Spring Actuator, since it uses PathPattern based URL matching. In this case, check this Spring Fox issue.

Rômulo Pereira
  • 331
  • 4
  • 6
1
SwaggerConfig.java 


@Configuration  
//Enable Swagger  
@EnableSwagger2  
public class SwaggerConfig   
{  
//creating bean  
    
@Bean  
public Docket api()  
{  
//creating constructor of Docket class that accepts parameter DocumentationType  
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("com.example.demo.controller")).paths(PathSelectors.regex("/api.*")).build();  
}  
}  


And Application.properties file :

spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Java lover
  • 21
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 12 '22 at 07:01