springboot整合swagger3
时间: 2023-10-14 07:05:48 浏览: 44
1. 添加依赖
在pom.xml中添加Swagger3的依赖:
```
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
```
2. 配置Swagger3
在Spring Boot的配置类中添加Swagger3的配置:
```
@Configuration
@EnableSwagger2WebMvc
public class Swagger3Config implements WebMvcConfigurer {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("API接口文档")
.description("API接口文档")
.version("1.0.0")
.build();
}
}
```
3. 启动应用程序
启动应用程序,访问http://localhost:8080/swagger-ui.html,即可看到Swagger3的API文档页面。