Last Updated: November 21, 2017
· zohebsait

Connection Pooling with Spring RestTemplate

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.

3 Responses
Add your response


Thank you very much for the info, great help.

over 1 year ago ·

What is the performance increase by using connection pool? When does it make sense to use it?


over 1 year ago ·

Thanks for this tip, just what I was looking for. Sadly this doesn't seem to be part of the official documentation.

over 1 year ago ·