Trying to use Feign Client with Eureka and Ribbon-
Have a service registered using Eureka with name-test-service.
Was able to use Ribbon and Eureka successfully as follows-
@Autowired
private LoadBalancerClient loadBalancer;
public void getEmployee() throws RestClientException, IOException {
ServiceInstance serviceInstance=loadBalancer.choose("test-service");
String baseUrl=serviceInstance.getUri().toString();
baseUrl=baseUrl+"/test";
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response=null;
try{
response=restTemplate.exchange(baseUrl,
HttpMethod.GET, getHeaders(),String.class);
}
This works correctly including load balancing.
Now tried to replace RestTemplate with Feign as follows-
@FeignClient(name="test-service")
public interface RemoteCallService {
@RequestMapping(method=RequestMethod.GET, value="/test")
public String resp();
}
And making the call with feign as follows-
@Autowired
private RemoteCallService loadBalancer;
public void getEmployee() throws RestClientException, IOException {
String data=loadBalancer.resp();
}
But this is not working. The Feign URL is not getting formed correctly. On debugging the FeignClient has the following values-
HardCodedTarget(type=RemoteCallService, name=test-service, url=http://test-service)
Can anyone tell what am i missing.
Thanks