Spring Cloud Config 客户端报错:No spring.config.import property has been defined

1、运行环境

Idea2020.1、jdk1.8、apache-maven-3.3.9、spring-cloud 2021.0.0、spring-boot 2.6.2

2、遇到的问题

No spring.config.import property has been defined

原因:2020.X.X版本官方重构了bootstrap引导配置的加载方式,需要添加相关依赖。

具体解释:bootstrap.properties比application.properties的优先级要高;

bootstrap.properties是系统级的资源配置文件,是用在程序引导执行时更加早期配置信息读取;

application.properties是用户级的资源配置文件,是用来后续的一些配置所需要的公共参数。

而在SpringCloud 2020.* 版本把bootstrap禁用了,导致在读取文件的时候读取不到而报错,所以我们只要把bootstrap从新导入进来就会生效了。

3、解决方法

加上一下依赖:


    org.springframework.cloud
    spring-cloud-starter-bootstrap

你可能感兴趣的:(SpringCloud,springBoot,Java,spring,maven,java)