As I know the RestTemplateBuilder is some kind of factory for RestTemplate. I have a few questions about using it:
Very often in examples there is something like this in
@Configurationclass:@Bean public RestTemplate getRestClient() { RestTemplate restClient = new RestTemplate(); ... return restClient; }Shouldn't
RestTemplatebe instantiated per@Serviceclass ? If so, how to customize it ?Spring reference says that
RestTemplateBuildershould be customized viaRestTemplateCustomizer. How to manage many URI's from many IP addresses with one builder ?How to add
BasicAuthenticationglobaly to allRestTemplatesviaRestTemplateBuilder, and is it a good practice?
Thanks for help.
UPDATE:
My application calls rest services from many servers at different IP's and urls - so logically for me is the situation when I have many RestTemplates.
I'm trying to have a factory (RestTemplateBuilder) per server - let's say servers A, B, C. I know how to add a basic authentication. But what for example when I want a basic authentication for server A but not for server B ?
I think about having one RestTemplateBuilder per server. I don't want to do this manually - I would prefer to use Spring mechanisms.
Any help ?