I have a provider in my eureka, like this:
Then I use restTemplate
to get the the message, like this:
@Autowired
RestTemplate restTemplate;
@RequestMapping("getInfo")
public String getMessage(){
return restTemplate.getForObject("http://microservice_provider/user/getUserInfo", String.class);
}
@LoadBalanced
@Bean
RestTemplate restTemplate()
{
return new RestTemplate();
}
}
But it never does works. It tells me:
So, what can I do to use like this successfully?
Create a
RestTemplate
bean and annotate you bean with@LoadBalanced
.That way, you can use the name of the microservice
microservice_provider
as part of the url.