解決:spring.profiles.active=dev 多實例不生效問題

問題

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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章