Swagger的使用
使用需求:由于在编写前后端分离项目时后端编码人员需要对接口进行测试,所以需要使用接口测试工具。小编推荐使用SpringDoc的方式来使用swagger因为正常引入springboot ✚ swagger会出现版本不兼容的情况。而且其会自动扫描接口无需配置。
- pom.xml填写内容
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
- application.properties 填写内容
yml方式请自行调整
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
- 编写配置类
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI springOpenAPI() {
return new OpenAPI().info(new Info()
.title("SpringDoc API Test")
.description("SpringDoc Simple Application Test")
.version("0.0.1"));
}
}
-
运行程序
在浏览器中输入 IP地址:端口号/swagger-ui/index.html -
运行效果