Spring Cloud Config-Client 無法獲取 Config-Server 在 github 上的配置文件的屬性值,竟然是因為!!!
版權聲明:本文為博主原創文章,遵循 CC 4.0 by-sa 版權協議,轉載請附上原文出處鏈接和本聲明。
Spring Cloud Config-Server 配置中心 配置文件放在github,配置文件均為bootstrap.yml(bootstrap.yml的優先級級比application.yml高,所以會先去github配置中心獲取信息)
運行 Spring Cloud Config-Client 應用程序時,報錯信息如下:
-
java.lang.IllegalArgumentException: Could
not resolve placeholder
'from' in value
"${from}"
-
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:
172) ~[spring-core-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:
124) ~[spring-core-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:
237) ~[spring-core-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:
211) ~[spring-core-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:
175) ~[spring-context-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:
839) ~[spring-beans-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:
1086) ~[spring-beans-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:
1065) ~[spring-beans-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:
584) ~[spring-beans-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:
91) ~[spring-beans-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:
373) ~[spring-beans-
5.0.
7.RELEASE.jar:
5.0.
7.RELEASE]
-
...
17 common frames omitted
!!!原因!!!
github上的配置文件的名字構成必須是: {application}-{profile}.properties
倉庫中的配置文件會被轉換成web接口,訪問可以參照以下的規則:/{application}/{profile}[/{label}]:
~: /{application}-{profile}.yml
~: /{label}/{application}-{profile}.yml
~: /{application}-{profile}.properties
~: /{label}/{application}-{profile}.properties
比如:config-client的配置文件信息如下:
-
eureka:
-
client:
-
serviceUrl:
-
defaultZone: http:
//peer1:1122/eureka/
-
spring:
-
application:
-
name: config-client
-
cloud:
-
config:
-
uri: http:
//localhost:9200/
-
label: master
-
profile: dev
-
-
server:
-
port:
9300
-
-
-
-
那么在github中的配置文件名必須是:config-client-dev.properties;否則程序啟動不起來。