【发布时间】:2016-09-10 07:32:48
【问题描述】:
我正在使用 Spring 4.0.3.RELEASE 版本。我能够成功拨打安静的电话。但是,我了解到 HTTP 连接很昂贵,并考虑使用连接池。我读了几篇像this 和this 这样的文章。当我在 Maven3 中包含依赖项并编译时,一切都很好。问题在运行时出现。 使用此代码,我得到 PoolingHttpClientConnectionManager 的类未找到异常。
public RestTemplate restTemplate(){
HttpHost host = new HttpHost("localhost", 9081);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// Increase max total connection to 200
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(50);
cm.setMaxPerRoute(new HttpRoute(host), 20);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(cm);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
httpClientBuilder.build());
return new RestTemplate(requestFactory);
}
使用此代码,我得到 HttpClients 的类未找到异常。
public RestTemplate restTemplate(){
RestTemplate restTemplate = new RestTemplate();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setConnectTimeout(20000);
requestFactory.setReadTimeout(20000);
restTemplate.setRequestFactory(requestFactory);
return restTemplate;
}
我在 Websphere 8.5 上进行部署。而且我尝试了从 4.0.1 到 4.5.2 的不同版本的 httpclient,它们的范围不同(提供,编译),但没有运气。 提前感谢您提供正确方向的任何提示。
【问题讨论】:
标签: httpclient connection-pooling websphere-8 resttemplate spring-4