nacos 2.0 版本在spring cloud 2022.0.0.0-RC2读取配置文件失败

报错

报错信息如下

Description:
No spring.config.import property has been defined

Spring 官方给出的解决方案如下

Add a spring.config.import=nacos: property to your configuration.
If configuration is not required add spring.config.import=optional:nacos: instead.
To disable this check, set spring.cloud.nacos.config.import-check.enabled=false.

出现原因

首先,自2021.0.5版本的 Spring Cloud 默认不再启用 bootstrap 包,因此应该将配置文件写在 application.yml 中,或手动在 maven 中导入 bootstrap 包。

解决方法

由于新版nacos要求我们在spring config import下配置新的nacos规则,我们仅需按照以下配置即可,按照nacos之前的的版本格式 p r e f i x − {prefix}- prefix{spring.profiles.active}.${file-extension}

spring:
  config:
    import:
      - optional:nacos:${spring.application.name}-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}-`` `
# 其他
如果进行修改后,还是注入为空,请检查nacos和本地的文件名称是否一致,是否在@Value注解是否采用正确格式`@Value("${pattern.dateformat}")`.
  • 10
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

过去日记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值