首先需要两套配置文件,后缀用-dev ,-prod区分。我的目录结构
1.首先在pom文件中引入
这个放在<build>标签后面,跟<build>同级
<!-- 打包的不同profile --> <profiles> <!-- 开发 --> <profile> <id>dev</id> <properties> <env>dev</env> </properties> <activation><activeByDefault>true</activeByDefault></activation> </profile> <!-- 生产 --> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> </profiles> 这个在<build>标签下 <resources> <resource> <directory>src/main/resources</directory> <excludes> <exclude> *.properties </exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>config-${env}.properties</include> <include>log4j.properties</include> </includes> </resource> </resources>
2.然后在context.xml 文件中 引入,这里俩都引进来,但是只会生效一个。
<context:property-placeholder file-encoding="utf-8" ignore-resource-not-found="true" ignore-unresolvable="false" location=" classpath:/config-prod.properties ,classpath:/config-dev.properties"/>
原文:https://www.cnblogs.com/onlyzhangmeng/p/15011276.html