Let us see How to fix Failed to start bean ‘documentationPluginsBootstrapper’; error. Check out our previous blogs on Swagger UI 2.x setup with Spring Boot application. and Swagger UI 3 Setup with Spring Boot Application However there may be a scenario where you can encounter the below error while using swagger-ui 3 and the idea is to use springdoc-openapi-ui instead.
Error Encountered
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
How to fix the error?
One solution could be to add the following line in the application properties file-
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
Use springdoc-openapi-ui
If the above still doesn’t work, then get rid of the springfox dependency and use springdoc-openapi-ui library instead.
Remove the springfox dependency from pom.xml
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
Or
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
and add the springdoc-openapi-ui dependency
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
After adding the springdoc-openapi-ui dependency, update your maven project and run the Spring Boot application main class, and hit the below URL in the browser.
http://localhost:8080/{context-path}/swagger-ui.html
If you are bootstrapping a new project the context path is not available so you can hit this in the browser
http://localhost:8080/swagger-ui.html or http://localhost:8080/swagger-ui/index.html
About Springdoc-openapi-ui
Springdoc-openapi-ui is a library that allows you to easily generate and embed an interactive API documentation UI in your Spring Boot application. It is based on the OpenAPI Specification (OAS), which is a standard for describing RESTful APIs.
If you are developing a RESTful API, I highly recommend using springdoc-openapi-ui. It is a great way to improve the discoverability, usability, and security of your APIs.thumb_upthumb_downuploadGoogle itmore_vert
Further Readings
More information here – https://springdoc.org/#migrating-from-springfox
Hope you are able to fix your error by following this blog. If not, please share your views in the comments section below and we will be happy to check and help 🙂