<profiles>
<profile>
<!--不同环境Profile的唯一id-->
<id>dev</id>
<properties>
<!--profiles.active是自定义的字段; 在build-resource里面引用-->
<profiles.active>dev</profiles.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
</properties>
<activation> <!--activation用来指定激活方式-->
<!--这个字段表示默认激活-->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
</profiles>
<build>
<!-- software.name、version自定义属性,取自properties节点 -->
<finalName>${software.name}-${version}</finalName>
<resources>
<resource>
<!-- project.basedir 取自应用内置名字,自动替换成项目地址-->
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources/</directory>
<!--打包时先排除掉三个文件夹-->
<excludes>
<exclude>dev/*</exclude>
<exclude>prod/*</exclude>
<exclude>test/*</exclude>
</excludes>
<includes>
<!--如果有其他定义通用文件,需要包含进来-->
<!--<include>messages/*</include>-->
</includes>
</resource>
<resource>
<!--这里是关键! 根据不同的环境,把对应文件夹里的配置文件打包-->
<directory>src/main/resources/${profiles.active}</directory>
</resource>
</resources>
</build>
pom详解
版权声明:本文为PJF1501105594原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。