Spring Cloud Config Client获取 Config Server配置服务器中的文件内容无法注入属性问题

Config Client 客户端无法获取Config Server服务器端配置文件内容需注意两个方面问题。

Spring Cloud Config Server 配置文件以GitHub作为远程仓库。

1、配置文件命名

使用Spring Cloud Config Client 获取 Config Server 配置文件时,如果Config Server端口不是8888时,则Config Client的配置文件应该设置为bootstrap.yml,而不是application.yml,bootstrap.yml加载顺序优先于application.yml,否则会获取失败。

如果配置文件为application.yml,报错信息如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'serverPort' in value "${serverPort}"
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:380) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapab

你可能感兴趣的:(Spring,IDEA,IDEA导入Maven,开发工具IDEA)