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

来源:互联网 发布:asp微信接口源码 编辑:程序博客网 时间:2024/05/17 10:26

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

spring.profiles.active=jdbcdev,certifyspring.mvc.view.prefix=/templates/spring.mvc.view.suffix=.html

配置方式:

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

<beans profile="dev">          <context:property-placeholder location="classpath:jdbc-dev.properties"/>  </beans>    <beans profile="prd">          <context:property-placeholder location="classpath:jdbc-prd.properties"/>      </beans>  

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

<context-param>          <param-name>spring.profiles.active</param-name>          <param-value>dev</param-value>  </context-param>
阅读全文
0 0
原创粉丝点击