What's the proper way of creating RestTemplate
instance in Spring
?
Let's say I have a service where I do multi-thread requests via rest template.
I found various variants in different tutorials:
1) create it when it is needed:
RestTemplate restTemplate = new RestTemplate();
2) declare it as bean:
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
(or what is the same way - in XML configuration file).
and then autowire it... Will it be always thread-safe in this case?
Is any performance difference? What is more "spring" style?