Spring3自定义环境配置 <beans profile="">
来源:互联网 发布:英国留学政策 知乎 编辑:程序博客网 时间:2024/05/17 04:45
Spring 3.1的功能,以后就不用为了区分Test, Dev, Production环境,搞几个只有细微区别的application.xml, application-test.xml及引用它们的web.xml了。
首先,将applicationContext.xml中的namespace从3.0升级到3.1.xsd, 然后就可以在文件末尾加入不同环境的定义,比如不同的dataSource
2.在web.xml里,你需要定义使用的profile,最聪明的做法是定义成context-param,注意这里定义的是default值,在非生产环境,可以用系统变量"spring.profiles.active"进行覆盖。
如果需要在eclipse设置development环境,在
3.在其他地方进行覆盖
3.1 在development和functional test启动Jetty前设置系统变量
3.2 在用到ApplicationContext的单元测试用例中,用 @ActiveProfiles定义
首先,将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>
Xml代码
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>production</param-value>
</context-param>
Run As --》Run Configurations... --》Environment 设置变量:
spring.profiles.active = development
3.在其他地方进行覆盖
3.1 在development和functional test启动Jetty前设置系统变量
Java代码
System.setProperty("spring.profiles.active", "development");
server.start()
Java代码
@ContextConfiguration(locations = { "/applicationContext.xml" })
@ActiveProfiles("test")
public class AccountDaoTest extends SpringTxTestCase {
}
演示了production,development,test,functional三个环境, 大家可以根据实际情况组合自己的环境管理。另外可以与Spring的properties文件加载时可顺位覆盖的特性(放一些不在版本管理中的xx.local.properties文件),更好的支持本地开发环境。
转至:http://blog.sina.com.cn/s/blog_546abd9f0101c6au.html
0 0
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3自定义环境配置 <beans profile="">
- Spring3.1+自定义环境配置 <beans profile="">
- spring3.1 profile 配置不同的环境
- spring3.1 profile 配置不同的环境
- spring3.1 profile 配置不同的环境
- spring3.1 profile 配置不同的环境
- Spring3.1中使用profile配置开发测试线上环境
- Spring3.1 profile 配置不同的数据库环境
- 使用Spring3.1后的的Profile配置使不同环境加载不同配置文件
- Profile-多环境配置
- profile分环境配置流程
- maven profile多环境配置
- websphere 配置库中已存在应用程序,异常处理
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- Oracle复习之12章--用户管理与权限分配
- 惊艳的App引导页:背景图片切换加各个页面动画效果
- 记一次计算机网络工程实验(2) 配置交换机
- Spring3自定义环境配置 <beans profile="">
- Nginx配置文件nginx.conf中文详解
- 第十一周 哈夫曼树
- spring+mybatis配置多数据源总结,重点是动态加载数据源,支持动态切换
- this.standing
- HTML5 postMessage 跨域交换数据
- 多线程下载资源
- Spring Boot基础|使用nohup运行jar文件
- MediaTek_ApSoC_SDK_4320_20150414编译问题