Add a spring.config.import=nacos: property to your configuration. If configuration is not required

 *   ┏┓   ┏┓+ +
 *  ┏┛┻━━━┛┻┓ + +
 *  ┃       ┃
 *  ┃   ━   ┃ ++ + + +
 *  ████━████ ┃+
 *  ┃       ┃ +
 *  ┃   ┻   ┃
 *  ┃       ┃ + +
 *  ┗━┓   ┏━┛
 *    ┃   ┃
 *    ┃   ┃ + + + +
 *    ┃   ┃
 *    ┃   ┃ +  神兽保佑
 *    ┃   ┃    代码无bug
 *    ┃   ┃  +
 *    ┃    ┗━━━┓ + +
 *    ┃        ┣┓
 *    ┃        ┏┛
 *    ┗┓┓┏━┳┓┏┛ + + + +
 *     ┃┫┫ ┃┫┫
 *     ┗┻┛ ┗┻┛+ + + +

问题描述

产生问题的原因是bootstrap.properties比application.properties的优先级要高
由于bootstrap.properties是系统级的资源配置文件,是用在程序引导执行时更加早期配置信息读取;
而application.properties是用户级的资源配置文件,是用来后续的一些配置所需要的公共参数。
但是在SpringCloud 2020.* 版本把bootstrap禁用了,导致在读取文件的时候读取不到而报错,所以我们只要把bootstrap重新导入进来就会生效了。

解决方法

方式一:添加配置

在yml或properties中添加如下配置

properties中添加
spring.cloud.nacos.config.import-check.enabled=false
yml中添加
spring:
    cloud:
        nacos:
            config:
                import-check:
                    enabled: false

方式二:添加pom
        <!--开启Spring Cloud 应用程序启动时加载bootstrap配置文件-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
            <version>3.1.4</version>
        </dependency>

希望看到这篇文章的小伙伴都能解决bug

  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值