spring RestTemplate (范例)的连接池
Xn_warm
・1 分钟阅读
如果使用MVC的spring RestTemplate来进行REST调用,必须意识到它不使用任何类型的HTTP连接池。
如果要使用连接池,则需要提供ClientHttpRequestFactory的另一个实现,一个好的选择是使用spring提供的org.springframework.http.client.HttpComponentsClientHttpRequestFactory()。
new org.springframework.web.client.RestTemplate(new HttpComponentsClientHttpRequestFactory())
当然,如果你查找HttpComponentsClientHttpRequestFactory的文档,你可以配置大量的连接池参数。