我有一个FeignClient接口,其名称我想从我的application.yml
文件加载,所以我这样做了:
@FeignClient(name = "${edgeServer}", configuration = BeansConfiguration.class)
在我的yml
文件中:
edgeServer: edge-server
但是我在运行时遇到异常:
java.lang.IllegalStateException:服务ID不合法主机名($ {edgeServer}) 在org.springframework.util.Assert.state(Assert.java:70)〜[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] 在org.springframework.cloud.netflix.feign.FeignClientsRegistrar.registerFeignClients(FeignClientsRegistrar.java:167)〜[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] 在org.springframework.cloud.netflix.feign.FeignClientsRegistrar.registerBeanDefinitions(FeignClientsRegistrar.java:92)〜[spring-cloud-netflix-core-1.3.1.RELEASE.jar:1.3.1.RELEASE] 在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.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:320)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] 在org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE] at 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] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)〜[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
那么该问题是否有任何解决方案,否则如何从我的yml属性中注入my name属性?
由于
答案 0 :(得分:0)
更新了您的行
@FeignClient(name = "${edgeServer}", configuration = BeansConfiguration.class)
与
@FeignClient(name = @Value("${edgeServer}"), configuration = BeansConfiguration.class)
希望这会奏效。
答案 1 :(得分:-1)
您是否在课堂上添加了@PropertySource("classpath:applciation.yml")
?