当前位置: 首页 > news >正文

重庆合川企业网站建设联系电话软文免费发布平台

重庆合川企业网站建设联系电话,软文免费发布平台,seo优化网站快速排名,windows10系统优化需求: 生产环境下,需要关闭swagger配置,避免接口暴露。 方法: 1、使用注解Value() 2、使用注解Profile({“dev”,“test”}) 表示在开发或测试环境开启,而在生产关闭。 3、使用注解ConditionalOnProperty(name “s…

需求:

生产环境下,需要关闭swagger配置,避免接口暴露。

方法:

1、使用注解@Value()
2、使用注解@Profile({“dev”,“test”}) 表示在开发或测试环境开启,而在生产关闭。
3、使用注解@ConditionalOnProperty(name = “swagger.enable”, havingValue = “true”) 然后在测试配置或者开发配置中 添加 swagger.enable = true 即可开启,生产环境不填则默认关闭Swagger。

方法一:使用注解@Value()

在Swagger2Config类里添加;
并需要在配置文件里添加一个swagger.enable属性,根据不同的application-xx.yml进行动态插入true或false即可。

@Configuration
@EnableSwagger2
public class Swagger2Config {@Value("${swagger.enable}")private Boolean enable;@Beanpublic Docket swaggerPersonApi10() {return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("com.unidata.cloud.logservice.api.controller")).paths(PathSelectors.any()).enable(enable)    //配置在该处生效.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/", "kangjia@xx.com")).description("logservice platform API v1.0").build();}
}

方法二:使用注解@Profile({“dev”,“test”}) 表示在开发或测试环境开启,而在生产关闭。

@Configuration
@EnableSwagger2
@Profile({"local", "dev"})
public class Swagger2Config {@Beanpublic Docket swaggerPersonApi10() {return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("com.unidata.cloud.logservice.api.controller")).paths(PathSelectors.any()).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/", "kangjia@xx.com")).description("logservice platform API v1.0").build();}
}

方法三:使用注解@ConditionalOnProperty(name = “swagger.enable”, havingValue = “true”) 然后在测试配置或者开发配置中 添加 swagger.enable = true 即可开启,生产环境不填则默认关闭Swagger。

1、使用注解 @ConditionalOnProperty(name = “swagger.enable”, havingValue = “true”)

@Configuration
@EnableSwagger2
//@ConditionalOnProperty(name ="enabled" ,prefix = "swagger",havingValue = "true",matchIfMissing = true   //matchIfMissing=true :为空则设为true,不合理
@ConditionalOnProperty(name = “swagger.enable”, havingValue =true)
public class Swagger2Config {@Beanpublic Docket swaggerPersonApi10() {return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("com.unidata.cloud.logservice.api.controller")).paths(PathSelectors.any()).enable(enable).build().apiInfo(apiInfo());}private ApiInfo apiInfo() {return new ApiInfoBuilder().version("1.0").title("xx项目:xx平台 Swagger2 文档 API").contact(new Contact("  xx团队", "https://www.xxx.com/", "kangjia@xxx.com")).description("logservice platform API v1.0").build();}
}

2、然后在测试配置或者开发配置中 添加 swagger.enable = true 即可开启,生产环境不写该配置则默认关闭Swagger。

#Swagger lock
swagger:    enabled: true

参考链接:https://www.dandelioncloud.cn/article/details/1593427183718813697

http://www.dt0577.cn/news/1876.html

相关文章:

  • 怎么用源码做网站视频宁波seo外包公司
  • 做电商网站需要多少钱企业网站seo托管怎么做
  • 政府网站的建设目标2024政治时政热点
  • 公司发布网站需要备案泉州百度竞价开户
  • 用哪个网站做相册视频文件夹北京seo收费
  • 桂林建设信息网站下载百度软件
  • 域名备案和网站备案的区别竞价推广代运营企业
  • 响应式网站设计图怎么做网站优化关键词价格
  • WordPress站点地图代码seo外包多少钱
  • asp网站出现乱码网络公司取什么名字好
  • 一个网站seo做哪些工作360应用商店
  • 网站暂时关闭 seo附近学电脑培训班
  • 商城网站的建设seo推广怎么样
  • 网站seo 优帮云公司网站制作公司
  • 外贸网站建设电话免费找精准客户的app
  • 网站页脚设计代码滨州网站建设
  • 西安微信网站建设百度搜索引擎入口官网
  • 企业网站服务器跟域名都需要交钱吗编程培训机构
  • 邯郸网站推广怎么做网络推广公司服务内容
  • 网站编辑怎么做内容分类下载优化大师并安装
  • 昆明360网站制作百度官方电话号码
  • 自己做相册的网站网络营销与直播电商专业就业前景
  • 河北搜恒不给做网站快速排名工具免费
  • p2p网站建设 上海用网站模板建站
  • 海尔网站建设最吸引人的营销广告词
  • 网站开发语言开发关键词有哪些?
  • 中国共产党两学一做网站女性广告
  • 访问不了服务器网站吗可以免费网络推广网站
  • 无锡做网站企业怎么弄一个自己的链接
  • 网站怎样做公众号网站排名优化软件有哪些