Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Deva for How to Create or configure Rest Template using @Bean in Spring Boot

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);

Viewing all articles
Browse latest Browse all 4

Trending Articles