springboot3.0中使用swagger
时间: 2024-05-24 11:08:09 浏览: 288
Spring Boot是一个快速开发的框架,而Swagger是一种API文档工具,可以帮助开发人员自动生成API文档,同时可以实现API的测试功能。在Spring Boot 3.0中使用Swagger可以遵循以下步骤:
1. 在pom.xml文件中添加Swagger依赖:
```
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
```
2. 创建Swagger配置类
创建一个Swagger配置类,用于配置Swagger的相关信息,如下所示:
```
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
```
3. 启用Swagger
在启动类上添加@EnableSwagger2注解,启用Swagger功能。
4. 查看API文档
在浏览器中访问http://localhost:port/swagger-ui.html,即可查看生成的API文档。
阅读全文
相关推荐


















