web项目使用profile实现配置切换

场景:一个web项目,可能有 (开发,测试,生产)几个环境 ,如db.properties url有多个,开发可能是 127.0.0.1 ,测试环境可能是 192.168.8.88,生产环境 www.xxx.com,需要根据环境使用相应的配置

问题:上线的时候可能会频繁的去改配置,导致一些不必出现的问题

实现方法:

  1.可以为db.properties分为上述三个环境 db_dev db_debug db_realease

   2.定义 beans 使用profile来指定具体的环境,如 realease

<beans profile="realease">
    <context:property-placeholder location="classpath:com/config/dev/db.properties" ignore-unresolvable="true"/>

</beans>

  3.在web.xml中增加spring可识别的配置

  

 <!-- 切换环境 -->
    <context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>realease</param-value>
    </context-param>

 


posted @ 2017-12-17 22:28  cacher  阅读(1044)  评论(0编辑  收藏  举报