前文
Swagger是一个用于设计、构建、文档化和使用RESTful Web服务的开源工具。Swagger3是Swagger的最新版本,它提供了许多新功能和改进。
跟着视频学习的时候发现Swagger在SpringBoot3中的引入方法发生了改变,发现网上大部分还是SpringBoot2的版本
准备
第一步
用maven构建一个SpringBoot3的项目,在依赖中引入
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.4</version>
</dependency>
注意版本要按照官方给出的新版,参照:Springdoc-OpenAPI
第二步
在application.yml中配置swagger的路径
# swagger-ui custom path
springdoc:
swagger-ui:
path : /swagger-ui.html
如果是properties文件,则配置
# swagger-ui custom path
springdoc.swagger-ui.path=/swagger-ui.html
然后在浏览器访问
然后,Swagger UI页面将在以下网址上提供,OpenAPI描述将在以下json格式的URL上提供:http://server:port/context-path/swagger-ui.html
http://server:port/context-path/v3/api-docs
成功进入