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

2019-02-20 06:37发布

问题:

I'm having a heck of a time getting a pooling connection manager to work for Resteasy clients. Deploying on 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();

I'm getting the error:

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]"}}

here is the entry from the POM:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
        <scope>provided</scope>
    </dependency>

The jar is already in the Wildfly modules directory, hence the provided scope.

How do I properly add and configure a pooled connection manager for Resteasy clients?

回答1:

Jars in the modules directory are mostly shielded from you and are there for the use of the server implementation. Exceptions are those that expose the Java EE APIs.

The easiest solution for you is to just include this jar in your application.

Alternatively, you could compose a jboss-deployment-structure.xml file as described in Class Loading in WildFly.

For example:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <dependencies>
            <module name="org.apache.httpcomponents"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>