Wildfly 8.1 ClassNotFound org.apache.http.conn.ClientConnectionManager

我有一段时间让一个联合连接管理器为Resteasy客户工作。 在Wildfly 8.1上部署。

import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; ... PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setMaxTotal(200); cm.setDefaultMaxPerRoute(20); HttpClient httpClient = new DefaultHttpClient(cm); ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient); ResteasyClient resteasyClient = new ResteasyClientBuilder().httpEngine(engine).build(); 

我收到了错误:

 19:04:59,355 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "ESM2.war")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"ESM2.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"ESM2.war\".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment \"ESM2.war\" Caused by: java.lang.RuntimeException: JBAS018757: Error getting reflective information for class com.xxx.esm2.server.webservices.rest.arcgis.ClientBean with ClassLoader ModuleClassLoader for Module \"deployment.ESM2.war:main\" from Service Module Loader Caused by: java.lang.NoClassDefFoundError: org/apache/http/conn/ClientConnectionManager Caused by: java.lang.ClassNotFoundException: org.apache.http.conn.ClientConnectionManager from [Module \"deployment.ESM2.war:main\" from Service Module Loader]"}} 

这是POM的条目:

   org.apache.httpcomponents httpclient 4.2.1 provided  

jar已经在Wildfly模块目录中,因此提供了范围。

如何为Resteasy客户端正确添加和配置池连接管理器?

模块目录中的jar大多数都是屏蔽的,可以使用服务器实现。 例外是那些公开Java EE API的例外。

最简单的解决方案是在您的应用程序中包含此jar。

或者,您可以编写一个jboss-deployment-structure.xml文件,如WildFly中的类加载中所述 。

例如: