springboot配置swagger
时间: 2023-04-30 09:01:20 浏览: 137
为了使用Swagger在Spring Boot中配置API文档,您需要以下步骤:
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配置类,如下所示:
```
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
```
3. 在应用程序启动后,您可以通过http://localhost:8080/swagger-ui.html访问Swagger UI。
请注意,以上步骤仅提供了最基本的Swagger配置,您可以根据需要进行更详细的配置。
阅读全文
相关推荐


















