Answer for Spring boot 2.*.* version.
I am using Spring boot 2.1.2.RELEASE and I also added RestTemplate in my project in a class where mail method exists.
@Beanpublic RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.setConnectTimeout(Duration.ofMillis(300000)) .setReadTimeout(Duration.ofMillis(300000)).build();}
and Used in my service or other classes like this
@AutowiredRestTemplate res;
and in methods
HttpEntity<String> entity = new HttpEntity<>(str, headers); return res.exchange(url, HttpMethod.POST, entity, Object.class);