swagger2(2.9.2) + springboot(2.6.0+)报错:
提示:这里简述项目相关背景:
springboot2.6与swagger2.9.2整合 报出空指针异常的,
org.springframework.context.ApplicationContextException:
Failed to start bean 'documentationPluginsBootstrapper'; 【重点】
nested exception is java.lang.NullPointerException
//中间错误信息省略
Caused by: java.lang.NullPointerException: null 【重点】
at springfox.documentation.spi.service.contexts.Orderings$8.compare(Orderings.java:112) ~[springfox-spi-2.9.2.jar:null]
at springfox.documentation.spi.service.contexts.Orderings$8.compare(Orderings.java:109) ~[springfox-spi-2.9.2.jar:null]
解决方案:
是因为springboot2.6.0 中将SpringMVC 默认路径匹配策略从AntPathMatcher更改为PathPatternParser application.properties(或application.yml)配置文件中加上这个路径配置
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
原因:springboot中请求路径与 Spring MVC 处理映射匹配的默认策略已从AntPathMatcher更改为PathPatternParser,需要更改回去,适应swagger中请求路径.
补充
一般空指针异常,都是数据找不到的情况的概率大点,如果下次遇到类似的问题,可以考虑路径配置关系,但前提要静下心来,研究每个小bug