在生產環境下禁用swagger


學習目標

快速學會使用注解關閉Swagger2,避免接口重復暴露。

使用教程

禁用方法1:使用注解@Profile({"dev","test"}) 表示在開發或測試環境開啟,而在生產關閉。(推薦使用)

禁用方法2:使用注解@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")  然后在測試配置或者開發配置中 添加 swagger.enable = true 即可開啟,生產環境不填則默認關閉Swagger.

@Configuration
@EnableSwagger2
//@Profile({"dev","test"})
@ConditionalOnProperty(name = "swagger.enable", havingValue = "true")
public class Swagger2Config {
/**
* 添加摘要信息(Docket)
*/
@Bean
public Docket controllerApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("接口文檔")
.description("具體包括XXX,XXX模塊...")
.contact(new Contact("Socks", null, null))
.version("版本號:1.0")
.build())
.select()
.apis(RequestHandlerSelectors.basePackage("com.hehe.controller"))
.paths(PathSelectors.any())
.build();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM