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个回答

u012358843
遗落的情叶 这篇文章是 eclipse spring+mybatis配置
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐