转:http://nassir.iteye.com/blog/1535799/
摘自springside3
Spring 3.1的功能,以后就不用为了区分Test, Dev, Production环境,搞几个只有细微区别的application.xml, application-test.xml及引用它们的web.xml了。
首先,将applicationContext.xml中的namespace从3.0升级到3.1.xsd, 然后就可以在文件末尾加入不同环境的定义,比如不同的dataSource
首先,将applicationContext.xml中的namespace从3.0升级到3.1.xsd, 然后就可以在文件末尾加入不同环境的定义,比如不同的dataSource
- <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"进行覆盖。
- <context-param>
- <param-name>spring.profiles.default</param-name>
- <param-value>production</param-value>
- </context-param>
3.在其他地方进行覆盖
3.1 在development和functional test启动Jetty前设置系统变量
- System.setProperty("spring.profiles.active", "development");
- server.start()
3.2 在用到ApplicationContext的单元测试用例中,用 @ActiveProfiles定义
- @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
http://huiseyiyu.iteye.com/blog/1202401
详细配置与使用:http://www.cnblogs.com/chanedi/archive/2012/01/12/2320837.html
相关推荐
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:p="http://www.springframework.org/schema/p" xmlns:c=...</beans>
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>WEB-INF/jdbc.properties</value> </list> </property> </bean> ...
<bean id="sayHelloJob" class="org.springframework.scheduling.quartz.JobDetailBean"> <property name="jobClass"> <value>com.test.Test</value> </property> </bean> <!-- 关键在如下两个触发器的...
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties" /> </bean> <!-- <bean id="dataSource" class="org....
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="mydataSource"> </property> <property name="mappingResources"> <list> <value>...
jdbc——内嵌事务 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> ...</beans>
<description>Spring公共配置文件</description> <!-- mes 的數據庫 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" ...
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> </bean> ...
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...
application.xml配置 ... <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- apache.dbcp连接池的配置 --> <bean id="dataSource" class="org.apache.commons.dbcp....
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"></ref> </property> <property name=...
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>classpath:jdbc.properties</value> </property> </bean> <bean id="dataSource" ...
封装通用的Spring3+Struts2+MyBatis3的CRUD+条件分页查询,Spring+Quartz调度,FunctionCharts图像化工具 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ...
webservice编写文档 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ... xsi:schemaLocation="http://www.springframework.org/schema/beans ...</beans>
struts2的入门开发,环境配置− <struts-config> <data-sources/> − <form-beans> <form-bean name="loginForm" type="test.form.LoginForm"/> </form-beans> <global-exceptions/> <global-forwards/> − <action-...
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ... xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" ...</beans>
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean> <!-- 配置數...
6 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 7 <property name="locations"> 8 <list> 9 <value>/WEB-INF/jdbc.properties</value> 10 ...