一、引入swagger依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<!--Swagger-UI API文档生产工具-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
二、配置swagger
@EnableSwagger2
@ConditionalOnProperty(value = {"swagger.enabled"})
@Configuration
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.hy.library"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("图书管理系统")
.description("接口文档")
.version("1.0")
.build();
}
}
验证url: http://localhost:8080/swagger-ui/index.html
注意
swagger3.0.0以后版本访问地址:http://localhost:8080/swagger-ui/index.html
swagger2.0.0以后版本访问地址http://localhost:8080/swagger-ui.html