spring boot 2 + feign + eureka client wont resolve service-name to URL

Found it! Its nothing to do with discovery, or config in general, it is because feign does not support context path!

In an attempt to 'dumb' down, I went on removing every single config to bare-minimum to keep the services up. It suddenly worked when I removed the context path of the second service. Thing is Feign+Ribbon do not support custom context path if set by other service. This is an old bug, still not fixed.

There are two possible solutions:

  1. Remove context path.
  2. Add context path in your Feign clients. So basically your Feign client becomes:

// This needs to be here for the formatting below to be right

@FeignClient(name = "secondservice/secondservice", configuration = FeignConfig.class)
public interface MessageServiceClient {
    @RequestMapping(method = RequestMethod.GET, value = "/dummy")
    public String getMessage();
}

I personally don't like either of the solutions. I like to have context path, well, to give context to a url, it becomes self-explanatory with a context. But it is a property of the other service (secondservice) and should be chosen/changed by that service. And so should not be hardcoded in dependent services. I would have liked it to be supported, but meanwhile, I am going to go for:

@FeignClient(name = "${dependencies.secondservice.url}")
public interface MessageServiceClient {....}

And in application.properties: dependencies.secondservice.url=secondservice/secondservice. This makes it clear that the property is owned by the dependency and not by this service.

Few more notes: 1. I could trace the request to SynchronousMethodHandler#executeAndDecode, response = client.execute(request, options);. Till here the url is note resolved. 2. The url being logged: GET http://secondservice/secondservice/dummy is in fact the correct URL, the first secondservice string gets replaced with IP after the log statement. Here is the documentation supporting that: https://cloud.spring.io/spring-cloud-static/Finchley.SR1/single/spring-cloud.html#_using_ribbon. Notice the url passed to restTemplate. This is what triggered the search for alternative causes.