一、jdk版本
swagger3对应jdk17及以上;
swagger2对应jdk8;
本文以jdk17为例
二、maven依赖
<!--swagger-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
三、yml配置
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
四、配置类
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info()
.title("测试文档")
.description("在线博客系统文档接口")
.version("v1"))
.externalDocs(new ExternalDocumentation()
.description("项目API文档")
.url("/"));
}
}
五、测试
@RestController
@RequestMapping("/test")
@Tag(name = "测试接口集")
public class TestController {
@GetMapping("/test")
public String helloWorld(){
return "你好,世界!";
}
}
六、接口地址
完成上述步骤后,请访问:http://localhost:8080/swagger-ui/index.html
博主设置的端口号是8080,大家根据自己的端口号进行更改