Springs RestTemplate default connection pool

Sam picture Sam · May 25, 2017 · Viewed 43.9k times · Source

Just wondering if RestTemplate out of the box uses connection pooling or does it simply establish a new connection each time ?

Answer

Praneeth Ramesh picture Praneeth Ramesh · May 25, 2017

By default RestTemplate creates new Httpconnection every time and closes the connection once done.

If you need to have a connection pooling under rest template then you may use different implementation of the ClientHttpRequestFactory that pools the connections.

new RestTemplate(new HttpComponentsClientHttpRequestFactory())