3

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?

INDRAJITH EKANAYAKE
  • 3,894
  • 11
  • 41
  • 63
user3528733
  • 1,259
  • 7
  • 20
  • 37

5 Answers5

20

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

Magesh
  • 221
  • 2
  • 10
  • 1
    This was it indeed in my code as well, I think you can simply resolve this question with your answer. – newhouse Sep 10 '19 at 12:45
1

use feign.client.config.airport-service.name,and configure in the property or yml. see https://github.com/spring-cloud/spring-cloud-openfeign/blob/master/docs/src/main/asciidoc/spring-cloud-openfeign.adoc

yanghui
  • 11
  • 1
0

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}"
  )
0

Resolving the Feign clients is one of the first things does during startup. Having this Problem can also relate to a misconfiguration. Ensure that your Application can find/detect/read the configuration file (application.yml/bootstrap.yml).

GJohannes
  • 1,408
  • 1
  • 8
  • 14
0

Use value property instead of name and it will work fine. Also check how to configure using application.yml in below code snippet

application.yml-->

airport:
  service:
    name: AIRPORT-SERVICE

Feign client interface-->

@FeignClient(value="${airport.service.name}")
abhinav kumar
  • 1,487
  • 1
  • 12
  • 20