今天将Spring Boot升级到2.6.x版本后,突然发现与Swagger集成时报如下错
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
又试了一下以前的版本没有问题,可以正常运行,经过测试将springboot版本降低到2.5及以下就可以正常运行,但是不可能为了用Swagger不用新版本的的SpringBoot,最后找了一下原因:
这是因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher,该注解可以更改匹配规则,所以解决办法:
在配置文件中添加:spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER来更改规则