springboot2.6.x + swagger2.x
<!-- springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- springfox-swagger-ui 默认的UI界面(默认访问地址:http://localhost:8081/swagger-ui.html) ,也可以导入不同的jar使用不同的UI界面 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
springboot主启动类添加:
@EnableSwagger2
启动成功后,访问: http://localhost:8080/swagger-ui.html
springboot2.6.x + swagger3.x
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
springboot主启动类添加: @EnableOpenApi
启动会报错: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:
matching-strategy: ant_path_matcher
启动成功后,访问: http://localhost:8080/swagger-ui/