Tag Archives: Failed to start bean ‘documentationPluginsBootstrapper’

[Solved] Springboot Integrate Swagger2 3.0.0 Error: Failed to start bean ‘documentationPluginsBootstrapper’

Add dependency

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>

Write swagger2 configuration class

@Enablewebmvc annotation can solve

Failed to start bean ‘documentationpluginsbootstrapper’

@Configuration
@EnableWebMvc
public class Swagger2Config {
}

test

Start the project and enter the web address

Swagger2.2.x. The website of version x is

http://localhost:8080/swagger-ui.html

For versions of swagger2 after 3.0.0, the website is

http://localhost:8080/swagger-ui/index.html

[Solved] Startup Error: Failed to start bean ‘documentationPluginsBootstrapper’

The error is spring boot version 2.6 or above and springfox swagger version 3.0 Compatibility issues with 0

Solution:

  • Downgrade springboot to 2.5.X and below
  • In the configuration in the spring configuration file: spring.mvc.pathmatch.matching-strategy=ant_path_matcher
  • However, the springfox bug has lasted for a long time and the team has not resolved it. So I suggest you use spring doc as a replacement

[Solved] Springboot integrate swagger Error: Failed to start bean ‘documentationPluginsBootstrapper‘

The compilation error of ‘documentationpluginsbootstrapper’ of failed to start bean appears after springboot integrates swagger:

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

Solution: add a comment in the startup class: @enablewebmvc

[Solved] Swagger Error: Failed to start bean ‘documentationPluginsBootstrapper’

Error cause: it may be caused by version mismatch. My spring boot is 2.6.0, but the spring cloud version needs to be compared in this way and cannot be degraded, so it is configured in this way

POM dependency

 <parent>
	 <groupId>org.springframework.boot</groupId>
	 <artifactId>spring-boot-starter-parent</artifactId>
	 <version>2.6.0</version>
	 <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger2</artifactId>
		<version>2.9.2</version>
	</dependency>
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger-ui</artifactId>
		<version>2.9.2</version>
	</dependency>
	<dependency>
		<groupId>com.google.guava</groupId>
		<artifactId>guava</artifactId>
		<version>25.1-jre</version>
	</dependency>
</dependencies>

Startup class:

@SpringBootApplication
@EnableDiscoveryClient
@EnableWebMvc // Comment out
public class UploadServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(UploadServiceApplication.class, args);
    }

}

This configuration may cause the UI page of swagger to fail to open, so the following configuration is required:

import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {

    /**
     * Accessing static resources
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * SpringBoot autoconfiguration itself does not map the /swagger-ui.html
         * This path is mapped to the corresponding directory META-INF/resources/
         * Use WebMvcConfigurerAdapter to publish the static files of swagger;
         */
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        //Map all /static/** accesses to the classpath:/static/ directory
        registry.addResourceHandler("/static/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX +"/static/");
        super.addResourceHandlers(registry);
    }
}