1.新建不同环境的配置
2.pom 配置profile
<!--id 与文件夹的名称对应-->
<profiles>
<profile>
<id>dev</id> <!--开发环境-->
<properties>
<deploy.type>dev</deploy.type>
</properties>
</profile>
<profile>
<id>pro</id> <!--生产环境-->
<properties>
<deploy.type>pro</deploy.type>
</properties>
</profile>
<profile>
<id>test</id> <!--测试环境-->
<properties>
<deploy.type>test</deploy.type>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
3.配置resource
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 打包资源 排除 -->
<excludes>
<exclude>test/*</exclude>
<exclude>pro/*</exclude>
<exclude>dev/*</exclude>
</excludes>
</resource>
<resource>
<!-- ${deploy.type} 对应 profile deploy.type -->
<directory>src/main/resources/${deploy.type}</directory>
</resource>
</resources>
</build>
4 执行打包命令
上图指定profile 为test,我们看看打出来的class 会把test下的配置打进去