Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException报错
情景还原
环境:
包名 | 版本 |
---|---|
SpringBoot | 2.6.3 |
springfox-swagger2 | 3.0.0 |
springfox-swagger-ui | 3.0.0 |
在整合SpringBoot和swagger过程中,使用如上配置,启动项目报错:
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
报错原因:Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher
解决办法
在application.yml
配置文件中添加如下配置:
spring:
mvc:
pathmatch:
# 将路径匹配策略改为ant_path_matcher,如果无效,则将其全部大写ANT_PATH_MATCHER
matching-strategy: ant_path_matcher
如果使用的是application.properties
则添加如下配置:
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
重新启动即可。
重启后找不到swagger-ui.html见Swagger2和SpringBoot整合后找不到swagger-ui.html
评论区