spring动态组装bean
背景介绍:
整合swagger时需要在生产环境中屏蔽掉swagger的地址,不能在生产环境使用
解决方案
使用动态profile在生产环境中不注入swagger的bean
swagger配置 profile="dev"
class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"
id="swagger2Config" />
mapping="swagger-ui.html" />
location="classpath:/META-INF/resources/webjars/"
mapping="/webjars/**" />
web.xml中上下文配置
spring.profiles.default
dev
本文采取的是作为web应用的上下文参数
注:还有多种配置方式:
作为DispatcherServlet的初始化参数
作为Web应用的上下文参数
作为JNDI条目
作为环境变量
作为JVM的系统属性
在继承测试上,使用@ActiveProfiles注解设置