Spring3自定义环境配置 <beans profile="">
2013-04-30 18:13
239 查看
摘自springside3
Spring 3.1的功能,以后就不用为了区分Test, Dev, Production环境,搞几个只有细微区别的application.xml, application-test.xml及引用它们的web.xml了。
首先,将applicationContext.xml中的namespace从3.0升级到3.1.xsd, 然后就可以在文件末尾加入不同环境的定义,比如不同的dataSource
Xml代码
<beans profile="test">
<jdbc:embedded-database id="dataSource">
<jdbc:script location="classpath:com/bank/config/sql/schema.sql"/>
</jdbc:embedded-database>
</beans>
<beans profile="production">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource"/>
</beans>
2.在web.xml里,你需要定义使用的profile,最聪明的做法是定义成context-param,注意这里定义的是default值,在非生产环境,可以用系统变量"spring.profiles.active"进行覆盖。
Xml代码
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
3.在其他地方进行覆盖
3.1 在development和functional test启动Jetty前设置系统变量
Java代码
System.setProperty("spring.profiles.active", "development");
server.start()
3.2 在用到ApplicationContext的单元测试用例中,用 @ActiveProfiles定义
Java代码
@ContextConfiguration(locations = { "/applicationContext.xml" })
@ActiveProfiles("test")
public class AccountDaoTest extends SpringTxTestCase {
}
在springside里有演示了production,development,test,functional三个环境, 大家可以根据实际情况组合自己的环境管理。另外可以与Spring的properties文件加载时可顺位覆盖的特性(放一些不在版本管理中的xx.local.properties文件),更好的支持本地开发环境,Jenkins上的functional test等其他环境。
详情:https://github.com/springside/springside4/wiki/Spring
详细配置与使用:/article/5063987.html
Spring 3.1的功能,以后就不用为了区分Test, Dev, Production环境,搞几个只有细微区别的application.xml, application-test.xml及引用它们的web.xml了。
首先,将applicationContext.xml中的namespace从3.0升级到3.1.xsd, 然后就可以在文件末尾加入不同环境的定义,比如不同的dataSource
Xml代码
<beans profile="test">
<jdbc:embedded-database id="dataSource">
<jdbc:script location="classpath:com/bank/config/sql/schema.sql"/>
</jdbc:embedded-database>
</beans>
<beans profile="production">
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource"/>
</beans>
2.在web.xml里,你需要定义使用的profile,最聪明的做法是定义成context-param,注意这里定义的是default值,在非生产环境,可以用系统变量"spring.profiles.active"进行覆盖。
Xml代码
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
3.在其他地方进行覆盖
3.1 在development和functional test启动Jetty前设置系统变量
Java代码
System.setProperty("spring.profiles.active", "development");
server.start()
3.2 在用到ApplicationContext的单元测试用例中,用 @ActiveProfiles定义
Java代码
@ContextConfiguration(locations = { "/applicationContext.xml" })
@ActiveProfiles("test")
public class AccountDaoTest extends SpringTxTestCase {
}
在springside里有演示了production,development,test,functional三个环境, 大家可以根据实际情况组合自己的环境管理。另外可以与Spring的properties文件加载时可顺位覆盖的特性(放一些不在版本管理中的xx.local.properties文件),更好的支持本地开发环境,Jenkins上的functional test等其他环境。
详情:https://github.com/springside/springside4/wiki/Spring
详细配置与使用:/article/5063987.html
相关文章推荐
- Spring3自定义环境配置 <beans profile="">
- Spring3.1+自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- hibernate 注解配置<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/X
- spring的环境配置(beans profile="xxx")
- Android自定义属性时format选项( <attr format="reference" name="background" /> )
- 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/>
- 关于<appSettings file="app.config" >引用外部文件的配置值
- springmvc加入配置<aop:aspectj-autoproxy proxy-target-class="true"/>报错 org/aspectj/lang/annotation/Aroun
- [网络收集]回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证
- (转)Android自定义属性时format选项( <attr format="reference" name="background" /> )
- Hibernate各种主键生成策略与配置详解【附1--<generator class="foreign">】
- [转]System.ArgumentException: 回发或回调参数无效。在配置中使用 < pages enableEventValidation="true"/> 或在页面中使用 <% @ Page EnableEventValidation="true" %> 启用了事件验证