项目场景:
1.springBoot搭建多环境配置文件目录
我打的是jar包
2.修改项目pom.xml文件
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<environment>dev</environment>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<environment>prod</environment>
</properties>
</profile>
</profiles>
找到build标签下的plugins标签,加载resource插件
<!-- resource插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>test-resources</id>
<!--目标执行的阶段,具体值看Maven的生命周期列表;-->
<phase>compile</phase>
<!--一个plugin的execution的目标列表,也就是上面的id-->
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<!-- 覆盖原有文件 -->
<overwrite>true</overwrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<!-- 待处理的资源定义 -->
<resources>
<resource>
<!-- 指定resources插件处理哪个目录下的资源文件 -->
<!--suppress UnresolvedMavenProperty -->
<directory>src/main/conf/${environment}</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
验证结果:
无profile选择情况下,会把src/main/resource/application.yml打进去
提示:profile选择dev
提示:profile选择prod