java.lang.ClassNotFoundException:org.apache.http.impl.conn.PoolingClientConnectionManager使用resteasy进行来自EJB的rest客户端调用

问题描述 投票:0回答:1

我在Wildfly 13上面临一个问题,当使用休息时很容易将服务称为客户端。

我在ear中部署了许多EJB项目。依赖关系由maven管理,除了wildfly 13应用程序服务器提供的库(来自模块文件夹)。我使用最新版本的JBoss Tools进行部署。

我的应用程序将一些休息服务作为服务器发布。当我打电话给那些网络服务(例如邮递员)时,一切都很好。 Wildfly提供的其余API org.jboss.resteasy.resteasy-jaxrs 3.5.1没有按预期发布。

但我的应用程序还需要连接到外部休息Web服务,这次是作为客户端。我编写了一个无状态EJB,实例化了一个针对提供的URL的WebTarget(这是外部休息服务的目标):

protected void setTarget(URL target) throws FmRestApiException {
    try {
        String sUrl = target.toString();
        this.target = ClientBuilder.newClient().target(sUrl);
    }
    catch(Exception e) {
        throw new FmRestApiException("Can't initialize FM Rest API to target "+target,e);
    }
}

但是当我发起呼叫时,Wildfly无法构建webtarget并且resteasy会抛出以下异常:

Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/conn/PoolingClientConnectionManager
    at org.jboss.resteasy.client.jaxrs.ClientHttpEngineBuilder4.build(ClientHttpEngineBuilder4.java:110)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.buildOld(ResteasyClientBuilder.java:381)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:390)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:38)
    at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
    at com.novarem.commons.fmapi.rest.AbstractFmApiRestClient.setTarget(AbstractFmApiRestClient.java:37)
    at fr.remmedia.fmadapter.FmRestApiGateway.init(FmRestApiGateway.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:122)
    at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:111)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
    at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:72)
    at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:89)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:105)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:237)
    ... 270 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.conn.PoolingClientConnectionManager from [Module "org.jboss.resteasy.resteasy-jaxrs" version 3.5.1.Final from local module loader @4c40b76e (finder: local module finder @2ea6137 (roots: /Library/JBoss/wildfly-remmedia-13/modules,/Library/JBoss/wildfly-remmedia-13/modules/system/layers/base))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)

我知道在以前版本的Wildfly中作为模块提供的resteasy和apache httpcomponents包之间的版本不兼容。但是在Wildfly 13中,org.jboss.resteasy.resteasy-jaxrs的版本为3.5.1版本,org.apache.httpcomponents的版本为httpclient版本4.5.2,httpcore为4.4.4,httpasyncclient为4.1.3,httpmime为4.5.2。

有人遇到同样的问题吗?另外,有没有人知道如何解决它?

rest ejb wildfly resteasy
1个回答
0
投票

我终于解决了这个问题。实际上,Wildfly默认不加载模块org.apache.httpcomponents,同时resteasy模块与它有依赖关系。因此,只需强制将模块加载到standalone.xml / domain.xml部署文件中,如下所示:

<subsystem xmlns="urn:jboss:domain:ee:4.0">
    <global-modules>
        <module name="org.apache.httpcomponents"/>
    </global-modules>
    ...
</subsystem>
© www.soinside.com 2019 - 2024. All rights reserved.