SpringBoot项目中启动Swagger如果报以下错误,可以通过两种方案解决:

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

这种错误是因为SpringBoot版本和Swagger版本不匹配导致的,博主Swagger和Swagger-UI用的都是Springfox 2.9.2的,SpringBoot是Idea中创建时自动提供的2.6.2的,Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher,两种解决方案如下:

1、修改SpringBoot的版本,去使用早期版本即可解决这个问题;

2、yml配置文件中添加配置:ant_path_matcherspring: mvc: pathmatch: matching-strategy: ant_path_matcher。

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐