idea中springboot项目加入swagger2,报空指针异常-爱代码爱编程
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
在引入正确的依赖后,在主类上加入了@EnableSwagger2注解,后来就报空指针异常
原因:Springfox使用的路径匹配基于AntPathMatcher,而Spring Boot 2.6.X使用的是PathPatternMatcher。
解决方法就是在application.yml文件中设置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
最后成功打开接口文档