spring.profiles.active 未生效问题解决

spring.profiles.active 未生效问题解决

解决spring.profiles.active配置未生效问题

问题解决历程:一开始配置未生效,然后根据网上的描述都配置了个遍,还是没有解决,最终自己发现启动类里面的配置写死了是dev,一直没有按照自己配置的来,我把第4点操作中的active profiles:去除为空之后,就可以了

1. 首先检查application.properties里面的spring.profiles.active配置,等号后面就是你要使用的环境

在这里插入图片描述

2. pom.xml配置是否有profiles

在这里插入图片描述

    <profiles>
        <profile>
            <id>local</id>
            <properties>
                <spring.profiles.active>local</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>dev</id>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <spring.profiles.active>test</spring.profiles.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <spring.profiles.active>prod</spring.profiles.active>
            </properties>
        </profile>
    </profiles>

配置上面的profiles,右侧maven会出现如下结构,勾选你要运行的环境:
在这里插入图片描述

3. pom.xml配置是否有resources

在这里插入图片描述

4. 启动类的配置是否写死了,写死就去除:本博主这里先前是写死的dev,坑坑坑

在这里插入图片描述

如果spring.profiles.active=local起作用了,可以看到运行窗口出现下面的标识:
在这里插入图片描述

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值