目录
问题
spring boot 2.x 运行指定配置(application-dev2.yml)文件,没有生效
mvn spring-boot:run -Pdev2
解决
spring-boot 2.x 使用mvn spring-boot:run -Dspring-boot.run.profiles=XXX
mvn spring-boot:run -Dspring-boot.run.profiles=dev2或者线上发布
java -jar -Dspring.profiles.active=dev2 demo-0.0.1-SNAPSHOT.jar
效果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-05-03 - [ main] d.s.d.DomeApplication : The following profiles are active: dev2
解决问题依据
https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/maven-plugin/examples/run-profiles.html

多实例配置过程

pom.xml
<profiles>
<profile>
<id>dev1</id>
<properties>
<spring.profiles.active>dev1</spring.profiles.active>
</properties>
</profile>
<profile>
<id>dev2</id>
<properties>
<spring.profiles.active>dev2</spring.profiles.active>
</properties>
</profile>
</profiles>
SpringBoot2.x指定配置文件运行
本文解决SpringBoot2.x环境下,运行指定配置文件(如application-dev2.yml)未生效的问题。通过调整mvn命令参数,如使用mvnspring-boot:run-Dspring-boot.run.profiles=dev2,或在线上发布时使用java-jar-Dspring.profiles.active=dev2,确保正确激活多实例配置。参考官方文档,了解如何在pom.xml中设置多实例配置。

15万+





