SpringBoot3使用Swagger
- 项目中的后端接口进行简单的前端展示
- 一、依赖引入
- 二、快速启动
- 1.在application.yml中配置
- 2.或者properties文件,则配置
- 3.启动项目访问swagger
项目中的后端接口进行简单的前端展示
Swagger是一个用于设计、构建、文档化和使用RESTful Web服务的开源工具。Swagger3是Swagger的最新版本,它提供了许多新功能和改进。
Swagger在SpringBoot3中的引入方法发生了改变,网上大部分还是SpringBoot2的版本
springboot版本3.2.4
一、依赖引入
用maven构建一个SpringBoot3的项目,在依赖中引入,在pom.xml中添加
<dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-starter-webmvc-ui</artifactId><version>2.0.4</version>
</dependency>
版本也可以使用新版,Springdoc-OpenAPI网站链接
二、快速启动
1.在application.yml中配置
# swagger-ui custom path
springdoc:swagger-ui:path : /swagger-ui.html
2.或者properties文件,则配置
代码如下(示例):
# swagger-ui custom path
springdoc.swagger-ui.path=/swagger-ui.html
3.启动项目访问swagger
访问http://localhost:9090/swagger-ui/index.html#/
其中的9090 改成你项目后端使用的端口,注意不能省略后面的index.html