0

我有一个 FeignClient 接口,我想从我的application.yml文件中加载一个名称,所以我这样做了:

@FeignClient(name = "${edgeServer}", configuration = BeansConfiguration.class)

在我的yml文件中:

edgeServer: edge-server

但我在运行时遇到异常:

java.lang.IllegalStateException: org.springframework.util.Assert.state(Assert.java:70) 的服务 id 不是合法主机名 (${edgeServer}) ~[spring-core-4.3.10.RELEASE.jar:4.3. 10.RELEASE] 在 org.springframework.cloud.netflix.feign.FeignClientsRegistrar.getName(FeignClientsRegistrar.java:238) ~[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] 在org.springframework.cloud.netflix.feign.FeignClientsRegistrar.registerFeignClient(FeignClientsRegistrar.java:181) ~[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.cloud .netflix.feign.FeignClientsRegistrar.registerFeignClients(FeignClientsRegistrar.java:167) ~[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.cloud.netflix.feign。 FeignClientsRegistrar.registerBeanDefinitions(FeignClientsRegistrar.java:92) ~[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:359) ~[spring-context -4.3.10.RELEASE.jar:4.3.10.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143) ~[spring-context-4.3.10.RELEASE.jar:4.3. 10.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] 在 org.springframework.context。注释.ConfigurationClassPostProcessor。processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320)~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)~[spring -context-4.3.10.RELEASE.jar:4.3.10.RELEASE] 在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-4.3.10.RELEASE.jar: 4.3.10.RELEASE] 在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] 在 org.springframework。 context.support.AbstractApplicationContext。invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring -context-4.3.10.RELEASE.jar:4.3.10.RELEASE]

那么这个问题有什么解决方案,否则我怎样才能让我的 name 属性从我的 yml 属性中注入?

谢谢

4

2 回答 2

0

更新了你的线路

@FeignClient(name = "${edgeServer}", configuration = BeansConfiguration.class)

@FeignClient(name = @Value("${edgeServer}"), configuration = BeansConfiguration.class)

希望这会奏效。

于 2017-10-25T10:54:15.180 回答
-1

你有没有@PropertySource("classpath:applciation.yml")在课堂上添加?

于 2017-10-25T11:20:48.877 回答