zoukankan      html  css  js  c++  java
  • 生产环境屏蔽swagger(动态组装bean)

    spring动态组装bean

    背景介绍:
    整合swagger时需要在生产环境中屏蔽掉swagger的地址,不能在生产环境使用

    解决方案
    使用动态profile在生产环境中不注入swagger的bean

    swagger配置 profile="dev"

    <beans profile="dev">
                <bean
                      class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"
                      id="swagger2Config" />
                <mvc:resources location="classpath:/META-INF/resources/"
                      mapping="swagger-ui.html" />
                <mvc:resources 
    location="classpath:/META-INF/resources/webjars/"
                      mapping="/webjars/**" />
          </beans>
    
    

    web.xml中上下文配置

    <!-- spring中活动的profiles 
           主要用来加载swagger
           开发环境设置为<u>dev</u>加载swagger的bean
           生产环境设置问<u>prod</u>不加载
       -->
      <context-param>
           <param-name>spring.profiles.default</param-name>
           <param-value><u>dev</u></param-value>
      </context-param>
    

    本文采取的是作为web应用的上下文参数
    :还有多种配置方式:

    • 作为DispatcherServlet的初始化参数
    • 作为Web应用的上下文参数
    • 作为JNDI条目
    • 作为环境变量
    • 作为JVM的系统属性
    • 在继承测试上,使用@ActiveProfiles注解设置
  • 相关阅读:
    hdu 1241 Oil Deposits(dfs入门)
    hdu 1022 Train Problem I(栈)
    DFS中的奇偶剪枝(转自chyshnu)
    ural 1821. Biathlon
    hdu 1237 简单计算器(栈)
    hdu 1010 Tempter of the Bone(dfs+奇偶剪枝)
    1119. Metro(动态规划,滚动数组)
    hdu 1312 Red and Black(dfs入门)
    C#匿名委托和匿名方法使用小技巧
    ubuntu下netbeans乱码问题解决
  • 原文地址:https://www.cnblogs.com/covet/p/10534805.html
Copyright © 2011-2022 走看看