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注解设置
  • 相关阅读:
    前端布局
    mysql默认数据库
    js 计算两个颜色之间的渐变色值 10个色值
    chrome network中的stalled阶段耗时含义
    linux软件源码安装与封装包安装
    如何分辨linux文件颜色
    linux 文件权限
    linux端口查看
    suse linux光盘挂载
    记一次tortoiese git误提交的问题
  • 原文地址:https://www.cnblogs.com/covet/p/10534805.html
Copyright © 2011-2022 走看看