dcohra
Last Updated: November 21, 2017
·
31.19K
· 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

17788

Thank you very much for the info, great help.

over 1 year ago ·
21197

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

Thanks

over 1 year ago ·
22841

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 ·