Swagger 怎么在生产开启 发布时自动关闭
可以通过注入true 或者 false 控制swagger的开启或关闭
@Configuration
@EnableSwagger2
public class Swagger2Config {
@Value("${swagger.enable}")
private Boolean enable;
@Bean
public Docket swaggerPersonApi10() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
.paths(PathSelectors.any())
.enable(enable) //true为开启 false为关闭
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.version("1.0")
.title("xx项目:xx平台 Swagger2 文档 API")
.contact(new Contact(" xx团队", "https://www.xx.com/", "xxx.com"))
.description("这是一款xxx系统")
.build();
}
}