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
@Configuration
class:@Bean public RestTemplate getRestClient() { RestTemplate restClient = new RestTemplate(); ... return restClient; }
Shouldn't
RestTemplate
be instantiated per@Service
class ? If so, how to customize it ?Spring reference says that
RestTemplateBuilder
should be customized viaRestTemplateCustomizer
. How to manage many URI's from many IP addresses with one builder ?How to add
BasicAuthentication
globaly to allRestTemplates
viaRestTemplateBuilder
, 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 ?