@Configuration
@EnableOpenApi
public class Swagger3Config {
//可以配置在application文件中
/**
* 与Spring 同一级的配置
*swagger:
* enable: true
* application-name: ${spring.application.name}
* application-version: 1.0
* application-description: springfox swagger 3.0整合Demo
* try-host: http://localhost:${server.port}
* http://localhost:8848/swagger-ui/index.html
*/
Boolean swaggerEnabled=true;//ture 启用Swagger3.0 fasle 禁用(生产环境要禁用)
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
// 是否开启
.enable(swaggerEnabled)
.select()
// 扫描的路径使用@Api的controller
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.apis(RequestHandlerSelectors.basePackage("xyz.ug666.springboot.controller"))
// 指定路径处理PathSelectors.any()代表所有的路径
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("Swagger3接口文档")
.description("适用于前后端分离统一的接口文档")
//作者信息
//.contact(new Contact("name","url", "email"))
.contact(new Contact("UG666","ug666.xyz", "2083206548@qq.com"))
.version("1.0")
.build();
}
}
在控制层加注解@Api(tags = "用户信息接口")
评论