3

我想从属性文件中设置@FeignClient 中的服务名称,如下所示:

@FeignClient("${service.users}")

并设置名称application.yml,例如:

service.users: user-service

user-service服务在 Eureka 中注册的名称在哪里。

我已经尝试过,但它不起作用。它抱怨无效的名称。

可以做这样的事情吗?

4

3 回答 3

1

这可以像这样完成。

@FeignClient(name="fd-mobileapi-service",url="${fdmobile.ribbon.listOfServers}")

fdmobile.ribbon.listOfServers : value =>> 这将是 application.properties 中的一个属性。

于 2016-02-17T07:43:01.453 回答
1

我尝试使用类似的配置:

@FeignClient(name = "${spring.application.name:optional.application.name}")

应用程序.yml,引导程序.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)

所以这个配置应该可以工作。我的建议是:

  1. 在运行时使用硬编码名称检查您的客户端 bean(您需要确保创建)
  2. 检查配置文件的可见性范围(配置文件中的变量可能超出范围)
  3. 检查您的 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有任何问题,您可以在此处找到解释:在此处输入链接描述

于 2016-05-24T14:02:45.883 回答
1

这是一个开放的问题。欢迎请求请求:-)

于 2015-11-17T18:22:25.933 回答