zoukankan      html  css  js  c++  java
  • 在生产环境下禁用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();
    }

  • 相关阅读:
    maven打包
    Description Resource Path Location Type Project configuration is not up-to-d
    GoldenGate
    maven打包 把要的依赖也打进去 配置
    mysql如何优化where子句
    根据状态计算操作状态
    kafka direct模式
    Kafka Connect
    Kafka Streams
    如何看源码
  • 原文地址:https://www.cnblogs.com/xiufengchen/p/10329997.html
Copyright © 2011-2022 走看看