<beans profile="test">
.......
</beans>
<beans profile="production">
.......
</beans>
1.在用到ApplicationContext的单元测试用例中,用 @ActiveProfiles
@ContextConfiguration(locations = { "/applicationContext.xml" })
@ActiveProfiles("test")
2.在development和functional test启动Jetty前设置系统变量
System.setProperty("spring.profiles.active", "development"); server.start()
3.在web.xml里
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
4.在非生产环境,可以用系统变量”spring.profiles.active”进行覆盖
Run As -->Run Configurations -->Environment
设置变量:spring.profiles.active = development
5.采用Spring框架的独立应用程序
GenericXmlApplicationContext ctx=new GenericXmlApplicationContext();
ctx.getEnvironment().setActiveProfiles("test");
ctx.load("classpath:applicationContext.xml");
ctx.refresh();
版权声明:本文为qq_30364013原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。