目录
首先Swagger(通过使用Springfox)的配置过程如下:
一、依赖
<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>
二、启动类添加注解
@SpringBootApplication
@EnableSwagger2
public class MyApp {
public static void main(String [] args){
SpringApplication.run(MyApp.class,args);
}
}
启动后就报错了:
org.springframework.context.ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException: Cannot invoke “org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.toString()” because the return value of “springfox.documentation.spi.service.contexts.Orderings.patternsCondition(springfox.documentation.RequestHandler)” is null
解决办法:
因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher,所以我们修改一下路径匹配,或者切换版本,我是直接在配置文件修改路径匹配的
//application.yml spring: mvc: pathmatch: matching-strategy: ant_path_matcher