Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'neo.hello' in value "${neo.hello}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:831) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 17 common frames omitted
git服务器上配置文件net-config-dev.properties
neo.hello=hello im dev updating
neo.hi=hi in dev
server:
port: 40000
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/maoyanchun/spring-cloud-config.git
search-paths: config-repo
username: username
password: *********
eureka:
client:
service-url:
defaultZone : http://127.0.0.1:10000/eureka
spring.cloud.config.name=neo-config
spring.cloud.config.profile=dev
spring.cloud.config.label=master
#开启Config服务发现支持
spring.cloud.config.discovery.enabled=true
#指定server端的name,也就是server
spring.cloud.config.discovery.service-id=config-server
config client的Controller:
@Value("${neo.hello}")
private String hello; //服务配置中心config-server获取
@RequestMapping("/hello")
public String hello(){
return this.hello;
}
config的server,client都注册到了eureka
因为spring boot是启动的时候才从配置文件中读取配置属性,配置文件在远程配置中心的话,注册中心的信息需要放在bootstrap.properties中才能启动优先读取,放在application.properties.会报该异常没发现属性
修改:
config client的bootstrap.properties
#服务注册中心的配置内容,指定服务注册中心的位置
eureka.client.service-url.defaultZone=http://127.0.0.1:10000/eureka
spring.cloud.config.name=neo-config
spring.cloud.config.profile=dev
spring.cloud.config.label=master
#开启Config服务发现支持
spring.cloud.config.discovery.enabled=true
#指定server端的name,也就是server
spring.cloud.config.discovery.service-id=config-server
正常启动client访问server端获取配置文件。