加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

profile属性

发布时间:2020-12-16 02:20:53 所属栏目:百科 来源:网络整理
导读:转:http://blog.csdn.net/wxwzy738/article/details/16968767 摘自springside3 Spring 3.1的功能,以后就不用为了区分Test,Dev,Production环境,搞几个只有细微区别的application.xml,application-test.xml及引用它们的web.xml了。 首先,将applicationCont

转:http://blog.csdn.net/wxwzy738/article/details/16968767


摘自springside3
Spring 3.1的功能,以后就不用为了区分Test,Dev,Production环境,搞几个只有细微区别的application.xml,application-test.xml及引用它们的web.xml了。

首先,将applicationContext.xml中的namespace从3.0升级到3.1.xsd, 然后就可以在文件末尾加入不同环境的定义,比如不同的dataSource
[html] view plain copy
  1. <beansprofile="test">
  2. <jdbc:embedded-databaseid="dataSource">
  3. <jdbc:scriptlocation="classpath:com/bank/config/sql/schema.sql"/>
  4. </jdbc:embedded-database>
  5. </beans>
  6. <beansprofile="production">
  7. <jee:jndi-lookupid="dataSource"jndi-name="java:comp/env/jdbc/datasource"/>
  8. </beans>

2.在web.xml里,你需要定义使用的profile,最聪明的做法是定义成context-param,注意这里定义的是default值,在非生产环境,可以用系统变量"spring.profiles.active"进行覆盖。
[html] view plain copy
  1. <context-param>
  2. <param-name>spring.profiles.default</param-name>
  3. <param-value>production</param-value>
  4. </context-param>
3.在其他地方进行覆盖

3.1 在development和functional test启动Jetty前设置系统变量
[java] view plain copy
  1. System.setProperty("spring.profiles.active","development");
  2. server.start()

3.2 在用到ApplicationContext的单元测试用例中,用 @ActiveProfiles定义
[java] view plain copy
  1. @ContextConfiguration(locations={"/applicationContext.xml"})
  2. @ActiveProfiles("test")
  3. publicclassAccountDaoTestextendsSpringTxTestCase{
  4. }

在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读