我正在使用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上。我尝试了不同版本的httpclient从4.0.1到4.5.2,具有不同的范围(提供,编译),没有运气。 提前感谢任何正确方向的提示。
答案 0 :(得分:1)
因此,它基本上是Websphere 8+版本的问题,包括httpclient及其jvm库。幸运的是,我们的Enterprise Websphere都是7.5.x版本。因此,如果我们将httpclient与耳朵捆绑在一起,则不会在生产或预生产中造成任何问题。
对于那些必须使用Websphere 8.x版本的用户,请使用共享隔离库方法as defined here。我将它用于我的本地8.5 Websphere,它的工作非常简洁。
答案 1 :(得分:0)
您应该停止该应用程序,然后转到websphere中的“管理模块”选项卡 并在“类加载器订单”组合框中选择“父项最后”项 然后开始申请。问题解决了......