最近在弄一個老項目,沒有用maven,springboot, 純springmvc項目。每次都需要手動切換配置,好麻煩的,於是就將Profile用起來。
在applicationContext.xml中加入
<!--profile 區分開-->
<beans profile="dev">
<util:properties id="config" location="classpath:dev.properties"/>
</beans>
<beans profile="pro">
<util:properties id="config" location="classpath:pro.properties"/>
</beans>
在web.xml中加入默認配置爲pro
<!--默認profile爲pro, 可以通過啓動加參數修改-Dspring.profiles.active=dev-->
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>pro</param-value>
</context-param>
開發的時候當然用的是dev, 在vm參數中加上-Dspring.profiles.active=dev 即可