我需要能够在 CXF JAX-WS 中可靠地获取客户端 IP 地址,因此我将以下代码添加到我的 Web 服务中:
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
在运行时提供必要模块的东西。我错过了什么?