2013-10-18 40 views
0

我需要的能力,reliably get client IP address in CXF JAX-WS,所以我下面的代碼添加到我的網絡服務:PhaseInterceptorChain和HttpServletRequest的導致AbstractEndpointFactory ClassNotFoundException的

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> 
012 (!)

但是,當我嘗試部署造成創建成功的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在運行時提供了必要的模塊缺失。我錯過了什麼?

回答

1

神祕解決了。對於所有的利益我提供這個問題的根源和解決辦法:

的問題是在這條線:

<version>2.4.0</version> 

也就是說,cxf-api神器的版本沒有整場比賽的CXF版本項目(和pom.xml)。

我不得不這樣做,以解決這個問題是到該行更改爲:

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

cxf.version早先定義爲2.7.1

結論:CXF依賴項/包/插件版本必須在整個pom.xml中匹配(否則您將獲得一些「紅鯡魚」)。

相關問題