- pom
<build>
节点下增加节点
<resources>
<resource>
<directory>
src/main/resources.${deploy.type}
</directory>
<excludes>
<exclude>
*.jsp
</exclude>
</excludes>
</resource>
<resource>
<directory>
src/main/resources
</directory>
</resource>
</resources>
- pom
<project>
节点下增加节点
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<deploy.type>dev</deploy.type>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<deploy.type>test</deploy.type>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<deploy.type>prod</deploy.type>
</properties>
</profile>
</profiles>
- 在
resources
文件夹的同级目录下创建以下文件夹
resources.dev
resources.test
resources.prod
-
将
resources
目录下需做环境隔离的配置文件分别拷贝到上一步创建的文件夹下, 并修改相应配置, 将公共的配置文件保留在resources
目录 -
maven打包编译命令
mvn clean package -DskipTests -Pdev
搞定