第一、资源文件位置
第二、spring配置文件中的配置
<!-- release环境 -->
<beans profile="release">
<context:property-placeholder ignore-resource-not-found="true"
location="classpath*:/envConf/application_release.properties"/>
</beans>
<!-- test环境 -->
<beans profile="test">
<context:property-placeholderignore-resource-not-found="true"
location="classpath*:/envConf/application_test.properties"/>
</beans>第三、spring配置文件中的配置
1)方式一
<context-param>
<param-name>spring.profiles.default</param-name>
<!-- 测试环境 -->
<param-value>test</param-value>
<!-- 正式环境 -->
<!-- <param-value>release</param-value> -->
</context-param> 2)方式二
<context-param>
<param-name>spring.profiles.active</param-name>
<!-- 测试环境 -->
<param-value>test</param-value>
<!-- 正式环境 -->
<!-- <param-value>release</param-value> -->
</context-param>
本文介绍了如何在Spring框架中根据不同环境(如测试环境和正式环境)进行配置,包括配置文件的位置及使用方法。通过两种方式激活特定环境配置:通过`spring.profiles.default`或`spring.profiles.active`参数。

4万+

被折叠的 条评论
为什么被折叠?



