【问题标题】:PhaseInterceptorChain and HttpServletRequest lead to AbstractEndpointFactory ClassNotFoundExceptionPhaseInterceptorChain 和 HttpServletRequest 导致 AbstractEndpointFactory ClassNotFoundException
【发布时间】:2013-10-18 13:47:41
【问题描述】:

我需要reliably get client IP address in CXF JAX-WS 的能力,因此我将以下代码添加到我的网络服务中:

Message message = PhaseInterceptorChain.getCurrentMessage();
HttpServletRequest request = (HttpServletRequest)message.get(AbstractHTTPDestination.HTTP_REQUEST);
request.getRemoteAddr();

为了成功完成构建,我必须添加以下导入:

import javax.servlet.http.HttpServletRequest;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
import org.apache.cxf.transport.http.AbstractHTTPDestination;

并将以下依赖项添加到我的pom.xml

    <dependency> <!-- PhaseInterceptorChain & Message -->
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-api</artifactId>
        <version>2.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency> <!-- HttpServletRequest -->
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <!-- scope>provided</scope -->
    </dependency>

但是当我尝试部署生成的成功(!)构建时,Tomcat(7.0.42)抛出异常并拒绝加载war文件:

org.springframework.beans.factory.BeanDefinitionStoreException: 
  Unexpected exception parsing XML document from class path resource [beans.xml]; 
    nested exception is org.springframework.beans.FatalBeanException: 
      Invalid NamespaceHandler class [org.apache.cxf.jaxws.spring.NamespaceHandler] for namespace [http://cxf.apache.org/jaxws]: 
        problem with handler class file or dependent class; 
          nested exception is java.lang.NoClassDefFoundError: org/apache/cxf/endpoint/AbstractEndpointFactory

...

Caused by: org.springframework.beans.FatalBeanException: 
  Invalid NamespaceHandler class [org.apache.cxf.jaxws.spring.NamespaceHandler] 
   for namespace [http://cxf.apache.org/jaxws]: 
    problem with handler class file or dependent class; 
     nested exception is java.lang.NoClassDefFoundError: org/apache/cxf/endpoint/AbstractEndpointFactory

...

Caused by: java.lang.ClassNotFoundException: org.apache.cxf.endpoint.AbstractEndpointFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)

显然,我的pom.xml 缺少一些在运行时提供必要模块的东西。我错过了什么?

【问题讨论】:

    标签: spring maven servlets jax-ws cxf


    【解决方案1】:

    谜团解开了。为了大家的利益,我提供了问题的根本原因和解决方案:

    问题出在这一行:

       <version>2.4.0</version>
    

    也就是说,cxf-api 工件的版本与整个项目的 CXF 版本不匹配(以及 pom.xml)。

    解决问题我所要做的就是将该行更改为:

    <version>${cxf.version}</version>
    

    其中cxf.version 之前定义为2.7.1

    结论:CXF 依赖项/包/插件版本必须在整个 pom.xml 中匹配(否则你会得到一些“红鲱鱼”)。

    【讨论】:

      猜你喜欢
      • 2012-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 2014-04-10
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多