【问题标题】:Feign Client and name from propertiesFeign Client 和属性中的名称
【发布时间】:2017-08-31 00:37:10
【问题描述】:

我有这样的,

@FeignClient(name = "${airport.service.name}")

我有类似的编译错误,

java.lang.IllegalStateException: 服务 id 不是合法的主机名 (${airport.service.name})

问题是如何将主机名形式applciation.yaml 传递给 FeignClient?

【问题讨论】:

  • 你在课堂上加了@PropertySource("classpath:applciation.yaml")吗?
  • 配置来自spring cloud config
  • 您确定您的配置包含密钥吗?
  • 是的,我找到了问题..错别字..

标签: java spring rest feign


【解决方案1】:

你可以指定url参数,而不是name参数:

@FeignClient(name = "${airport.service.name}", url = "${airport.service.url}")

如果你需要使路径可配置,你可以使用类似的东西

 @RequestMapping(
            path = "${airport.service.path}"
  )

【讨论】:

    【解决方案2】:

    虽然已经很晚了,但我正在更新我的答案,因为我在 spring cloud 中使用 feign 客户端时遇到了这个异常(java.lang.IllegalStateException:Service id not legal hostname) 根本原因是 feign 客户端不接受低于分数的服务名称,请通过以下链接。为了解决这个问题,我用 hypen(school-service) 而不是 understore(school_service) 重命名了 feign 客户端使用的服务名称

    Github link - spring-cloud-netflix - Issue Github link - spring-cloud-netflix - commit

    【讨论】:

    • 这在我的代码中确实也是如此,我想你可以用你的答案简单地解决这个问题。
    【解决方案3】:

    使用feign.client.config.airport-service.name,并在属性或yml中配置。 见https://github.com/spring-cloud/spring-cloud-openfeign/blob/master/docs/src/main/asciidoc/spring-cloud-openfeign.adoc

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 2018-03-21
      • 2011-10-15
      • 1970-01-01
      • 2013-09-14
      • 2018-01-29
      • 1970-01-01
      • 2015-08-07
      相关资源
      最近更新 更多