参考文章网址:
http://www.cnblogs.com/yjmyzz/p/3941043.html
项目开发好以后,通常要在多个环境部署,我公司有三套:prod,dev,test,数据库有两套mysql,oracle
项目的相关环境的目录:
pom.xml中的profiles片段配置如下:
<span style="white-space:pre"> </span><profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<span style="white-space:pre"> </span><profile>
<id>mysql</id>
<properties>
<db>mysql</db>
</properties>
</profile>
<profile>
<id>oracle</id>
<span style="white-space:pre"> </span><activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<db>oracle</db>
</properties>
</profile>
</profiles>
项目工程中spring.xml文件部分内容:
<context:property-placeholder location="classpath:conf/${env}/jdbc-${db}-${env}.properties" />
<util:properties id="config" location="classpath:conf/${env}/app-${env}.properties" />
各属性节点的值,用占位符"${属性名}"占位,maven在package时,会根据profile的环境自动替换这些占位符为实际属性值。