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

Mat*_*att 2 java httpclient classnotfoundexception wildfly

我很难让一个池连接管理器为 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();
Run Code Online (Sandbox Code Playgroud)

我收到错误:

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]"}}
Run Code Online (Sandbox Code Playgroud)

这是 POM 中的条目:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
        <scope>provided</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

该 jar 已经位于 Wildfly 模块目录中,因此是提供的范围。

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

Ste*_*e C 6

模块目录中的 jar 大部分对您来说都是屏蔽的,并且供服务器实现使用。例外是那些公开 Java EE API 的例外。

对您来说最简单的解决方案是将这个 jar 包含在您的应用程序中。

或者,您可以按照WildFly 中的类加载中的描述编写 jboss-deployment-struct.xml 文件。

例如:

<?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>
Run Code Online (Sandbox Code Playgroud)

  • 我最终所做的是将“Dependency: org.apache.httpcomponents”添加到清单文件中。我仍然不明白为什么 WildFly 模块/模块/基本目录中的一些 jar 被加载,而有些则没有。 (2认同)