配置动态调整active参数:
1.bootstrap.yml中:
spring:
profiles:
active: @spring.profiles.active@ #占位符 替换
2.pom.xml中配置:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--开启过滤,用指定的参数替换directory下的文件中的参数-->
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>
</profiles>
3.打包时选择profile(运行时也一样):
等价于:mvn clean package -P prod
也可以运行jar包时添加参数: java -jar app.jar --spring.profiles.active=dev