父级pom文件中加入此配置
<build><!--默认资源目录--><resources><resource><directory>src/main/resources</directory><filtering>true</filtering><!--是否使用过滤器--></resource></resources>
</build><profiles><!--开发库环境--><profile><id>dev</id><properties><profiles.activation>dev</profiles.activation></properties></profile><!--测试库环境--><profile><id>test</id><activation><activeByDefault>true</activeByDefault></activation><properties><profiles.activation>test</profiles.activation></properties></profile><!--正式库环境--><profile><id>release</id><properties><profiles.activation>release</profiles.activation></properties></profile>
</profiles>
启动文件web.xml加入
<context-param><param-name>spring.profiles.default</param-name><param-value>dev</param-value>
</context-param>
<context-param><param-name>spring.profiles.active</param-name><param-value>${profiles.activation}</param-value>
</context-param>
初始化xml中加入
<beans profile="dev"><context:property-placeholder location="classpath:dev.properties" file-encoding="utf-8" ignore-unresolvable="true" order="2"/><context:property-placeholder location="classpath:application.properties" file-encoding="utf-8" ignore-unresolvable="true" order="1"/></beans><beans profile="test"><context:property-placeholder location="classpath:test.properties" file-encoding="utf-8" ignore-unresolvable="true" order="2"/><context:property-placeholder location="classpath:application.properties" file-encoding="utf-8" ignore-unresolvable="true" order="1"/></beans>
</beans>
感谢观看,可以在微信搜索公众号 “威信交流”,关注一波呗