问题
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