mdxdjhpkpk
ellis-L
采纳率0%
2016-12-27 09:14 阅读 3.6k

SpringCloud config 注册服务后client取值问题

将SpringCloud的config部署注册到eureka上的时候遇到如下报错,哪位大神指点一下。谢谢

配置信息:

testConfig-test.properties
from=git-test-1.0

Service :

@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class TestSpringCloudConfigApplication {

public static void main(String[] args) {
    SpringApplication.run(TestSpringCloudConfigApplication.class, args);
}

}

application.properties(service)

server.port=7001
spring.application.name=config-server

git管理配置

spring.cloud.config.server.git.uri=xxx/test_spring_cloud_config
spring.cloud.config.server.git.searchPaths=config
spring.cloud.config.server.git.username=xxx
spring.cloud.config.server.git.password=xxx

eureka.client.service-url.defaultZone=http://localhost:7070/eureka/

Client:

@EnableDiscoveryClient
@SpringBootApplication
public class TestSpringCloudConfigClient
{

public static void main(String[] args) {
    new SpringApplicationBuilder(TestSpringCloudConfigClient.class).web(true).run(args);
}

}

@RefreshScope
@RestController
public class TestController
{
@Value("${from}")
private String from;

@RequestMapping("/from")
public String from()
{
    return this.from;
}

public void setFrom(String from)
{
    this.from = from;
}

public String getFrom()
{
    return from;
}

}

报错:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'from' in string value "${from}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:236) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:823) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1084) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1064) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 35 common frames omitted

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐