A RestTemplate bean can be annotated with @LoadBalanced to mark it for customization with the RibbonClientHttpRequestFactory so that Eureka discovered names are resolved to real resource URLs. See Microservices with Spring - Load balanced RestTemplate.
In Spring Boot 1.4, it is now recommended to inject a RestTemplateBuilder bean into Rest client classes rather than use RestTemplate directly. See Spring Boot Reference - Calling REST services.
When a Rest client is created with a RestTemplateBuilder, the RestTemplate is not automatically customized with the RibbonClientHttpRequestFactory and names are not resolved against Eureka. Ideally, this customization should happen when Ribbon Http client is enabled (property ribbon.http.client.enabled).
I've used this as a workaround - this is a possible way of fixing: Spanners-mvc RestClientConfig
Integration with the builder is a good idea. RibbonClientHttpRequestFactory is no longer the default. It does not support some basic http methods.
Why not just do this?
@Bean
@LoadBalanced
public RestTemplate restTemple() {
return new RestTemplateBuilder().build();
}
Closing this due to inactivity. Please re-open if there's more to discuss.
Most helpful comment
Why not just do this?