目錄
問題
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>