Dibya
Dibya

Reputation: 101

Upgraded Spring Boot to 2.7.0- Failed to start bean 'documentationPluginsBootstrapper

Upgrading Springboot version- 2.7.0 ext { springBootVersion = '2.7.0' wsdl2javaVersion='0.10' cxfVersion='3.4.3' }

Cloud Version: ext { set('springCloudVersion', '2021.0.3') }

Springfox: //swagger compile "io.springfox:springfox-swagger2:2.9.2" compile "io.springfox:springfox-swagger-ui:2.9.2"

Getting Error: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerExceptionclass

Any lead is really appreciate to fix this issue.

Upvotes: 10

Views: 27833

Answers (4)

Fullstack Hamster
Fullstack Hamster

Reputation: 1

After several hours of search:

java -version

is also important. I have JDK 11.smth, so I had to downgrade Spring to 2.5.3 - even 2.6.0 gave the same issue. Now it works with both Swagger 2 and OAS3.

17-th java is ok with suggestions above.

Upvotes: 0

Octavia
Octavia

Reputation: 242

Add this bean to your swagger configuration

@Bean
    public WebMvcRequestHandlerProvider webMvcRequestHandlerProvider(Optional<ServletContext> servletContext, HandlerMethodResolver methodResolver, List<RequestMappingInfoHandlerMapping> handlerMappings) {
        handlerMappings = handlerMappings.stream().filter(rh -> rh.getClass().getName().contains("RequestMapping")).toList();
        return new WebMvcRequestHandlerProvider(servletContext, methodResolver, handlerMappings);
    }

and make sure you used DocumentationType.OAS_30 in your config

also, add this in your proerties file:

spring.mvc.pathmatch.matching-strategy= ANT_PATH_MATCHER

this worked for me, BUT now I can access only the endpoints directly, and not the swagger page

Upvotes: 0

meher
meher

Reputation: 81

In the application.properties

spring.mvc.pathmatch.matching-strategy= ANT_PATH_MATCHER

Upvotes: 6

Arya C Achari
Arya C Achari

Reputation: 39

If you are using the spring-boot version 2.7.x, springfox, and the actuator use this dependency (I don't know will it work for your case, at the time I'm doing this, version of spring-boot 2.7.1)

  1. In pom.xml

     <!-- API documentation. Refer the link http://springfox.github.io/springfox/docs/2.7.0/#introduction -->
     <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger2</artifactId>
         <version>2.7.0</version>
     </dependency>
    
  2. Then in the SwaggerConfig configuration class

     /* .pathMapping("/") can resolve the conflict between actuator and springfox */
     @Bean
     public Docket api() {
         return new Docket(DocumentationType.SWAGGER_2)
             .select()
             .apis(RequestHandlerSelectors.any())
             .paths(PathSelectors.any())
             .build()
             .pathMapping("/");
     }
    
  3. Then

if you're using the application.properties

spring.mvc.pathmatch.matching-strategy= ANT_PATH_MATCHER

if you're using the application.yml

    spring:
      #Use this to befriend spring-boot-starter-actuator & springfox-boot-starter
       mvc:
         pathmatch:
           matching-strategy: ANT_PATH_MATCHER

Upvotes: 3

Related Questions