解决: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>
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值