报错信息如下
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 包
然后,在 application.yml 中,按照以下方式配置
spring:
application:
name: XXXX
cloud:
nacos:
server-addr: XX.XX.XX.XX:8848
config:
group: XXXX
namespace: XXXX
# SpringCloud 2021版本之后,需要用以下方式导入nacos的配置文件
config:
import: nacos:XXXX.yml
问题解决。