Connection Pooling with Spring RestTemplate

Zoheb Sait
Zoheb Sait
Published in
1 min readNov 2, 2016

--

If you are using Spring MVC’s RestTemplate to make REST calls, it is important to realize that it doesn’t use HTTP connection pooling of any kind, and will establish and close a connection every time you make a REST call.

If you want to use connection pooling, you would need to provide another implementation of ClientHttpRequestFactory. A good option is to use the org.springframework.http.client.HttpComponentsClientHttpRequestFactory() which is provided with Spring.

new org.springframework.web.client.RestTemplate(new HttpComponentsClientHttpRequestFactory())

Of course, if you look up the documentation for HttpComponentsClientHttpRequestFactory, you can configure a lot of the connection pooling parameters.

--

--