SpringCloud config 注册服务后client取值问题
澳门赌场开户
澳门赌场开户
当前位置 : 澳门赌场开户 > 网上赌博新址

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

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

配置信息:

testConfig-test.propertiesservice

from=git-test-1.0

Service :

@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class TestSpringCloudConfigApplication {
public static void mainString[] args {
    SpringApplication.runTestSpringCloudConfigApplication.class, args;
}
}

application.propertiesservice

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 mainString[] args {
    new SpringApplicationBuilderTestSpringCloudConfigClient.class.webtrue.runargs;
}
}

@RefreshScope
@RestController
public class TestController
{
@Value"${from}"
private String from;
@RequestMapping"/from"
public String from
{
    return this.from;
}

public void setFromString 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.parseStringValuePropertyPlaceholderHelper.java:174 ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholdersPropertyPlaceholderHelper.java:126 ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholdersAbstractPropertyResolver.java:236 ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholdersAbstractPropertyResolver.java:210 ~[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValuePropertySourcesPlaceholderConfigurer.java:172 ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValueAbstractBeanFactory.java:823 ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependencyDefaultListableBeanFactory.java:1084 ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependencyDefaultListableBeanFactory.java:1064 ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.injectAutowiredAnnotationBeanPostProcessor.java:585 ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.injectInjectionMetadata.java:88 ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValuesAutowiredAnnotationBeanPostProcessor.java:366 ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
... 35 common frames omitted

已找到原因,config-client的spring.application.name必须和自己的配置文件名相匹配。

例如配置文件为:
testConfig-test.properties

这个时候对应的config-cleint的spring.application.name=testConfig

客户端的属性配置呢?客户端需要指向配置服务器。而且testConfig-test.properties能不能改个名?

栏目列表

广告位

澳门赌场开户