Feign Client and name from properties

情到浓时终转凉″ 提交于 2020-01-05 03:33:49

问题


I have sth like this,

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

And I have compilation error like,

java.lang.IllegalStateException: Service id not legal hostname (${airport.service.name})

The question is how can I pass hostname form applciation.yaml to FeignClient?


回答1:


Though it is late, I am updating my answer since I faced this exception (java.lang.IllegalStateException: Service id not legal hostname) while using feign client in spring cloud The root cause is feign client won't accept service name with under score, Please go through the below link. To resolve this issue I renamed the service name to be used by feign client with hypen(school-service) instead of understore(school_service)

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




回答2:


You can specify url parameter, rather than name parameter:

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

and if you need to make path configurable, you can use something like

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


来源:https://stackoverflow.com/questions/43230475/feign-client-and-name-from-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!