spring.profiles.active 针对多种启动环境的spring配置

我们的工程一般在会跑在正式环境、测试环境上,当打包或者运行的时候,切换数据库信息可能会是很麻烦的问题。

配置方式:

1、在spring配置文件中配置两种环境信息

[html] view plain copy

  1. <beans profile="dev">  
  2.         <context:property-placeholder location="classpath:jdbc-dev.properties"/>  
  3.     </beans>  
  4.     <beans profile="prd">  
  5.         <context:property-placeholder location="classpath:jdbc-prd.properties"/>  
  6.     </beans>  


2、在web.xml中配置使用哪种环境信息,tomcat启动的时候自动去加载对应的环境信息

[html] view plain copy

  1. <context-param>  
  2.         <param-name>spring.profiles.active</param-name>  
  3.         <param-value>dev</param-value>  
  4.     </context-param>  

猜你喜欢

转载自my.oschina.net/architectliuyuanyuan/blog/1806659