我尝试使用类似的配置:
@FeignClient(name = "${spring.application.name:optional.application.name}")
应用程序.yml,
bootstrap.yml:
spring:
application:
name: my-test-application
启动后查看日志
2016-05-24 16:11:00 [hystrix-my-test-application-1] INFO o.s.c.a.AnnotationConfigApplicationContext.prepareRefresh...
我也在zookeeper active service中找到了
>ls /service/my-test-application
[8668663c-cce1-4181-94de-4ccaacefa7e3]
在调试模式客户端 bean 中检查 - 它已创建
HardCodedTarget(type=EventBusClient, name=fnma-cp-test, url=http://my-test-application)
所以这个配置应该可以工作。
我的建议是:
- 在运行时使用硬编码名称检查您的客户端 bean(您需要确保创建)
- 检查配置文件的可见性范围(配置文件中的变量可能超出范围)
- 检查您的 application.yml - 我不确定,spring 社区默认保留变量名称“service.users”(可能需要添加特殊依赖项)。或者如果你不知道依赖但需要使用一个,
请创建下一个文件结构:
application.yml
META-INF
|-additional-spring-configuration-metadata.json
additional-spring-configuration-metadata.json 应该有这样的东西
{
"properties": [
{
"name": "service.users",
"type": "java.lang.String",
"description": "Description for service.users.",
"defaultValue": "Some_Value"
}
]
}
无论如何,如果 additional-spring-configuration-metadata.json 有任何问题,您可以在这里找到解释:enter link description here