非maven springboot配置多环境profile

最近在弄一个老项目,没有用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 即可

猜你喜欢

转载自blog.csdn.net/favormm/article/details/95306492