[webservice] spring 整合 Apache CXF

代码参考:

[webservice] CXF 处理Map 类型数据

web.xml添加如下配置:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:cxf-config.xml</param-value>
    </context-param>
     <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
     
    <!-- CXF webservice 配置 -->
    <servlet>
    <servlet-name>cxf</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    </servlet>
    
    <servlet-mapping>
    <servlet-name>cxf</servlet-name>
    <url-pattern>/webservice/*</url-pattern>
    </servlet-mapping>

cxf-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:core="http://cxf.apache.org/core"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
    
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    
    <jaxws:endpoint id="helloWS" address="/hello" implementor="com.xwolf.cxf.dao.impl.HelloWSImpl">
    
    </jaxws:endpoint>

</beans>

cxf-servlet.xml 所在jar文件为:cxf-rt-transports-http-2.7.7.jar

项目启动后,输入地址: http://localhost:8080/blog/webservice/hello 抛出如下异常:

警告: Interceptor for {http://impl.dao.cxf.xwolf.com/}HelloWSImplService has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No binding operation info while invoking unknown method with params unknown.
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:59)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:57)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)

 

访问如下地址: http://localhost:8080/blog/webservice/hello?wsdl 才可以正常访问。

 

  <?xml version="1.0" ?> 
- <wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.dao.cxf.xwolf.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://dao.cxf.xwolf.com/" name="HelloWSImplService" targetNamespace="http://impl.dao.cxf.xwolf.com/">
  <wsdl:import location="http://localhost:8181/blog/webservice/hello?wsdl=IHelloWS.wsdl" namespace="http://dao.cxf.xwolf.com/" /> 
- <wsdl:binding name="HelloWSImplServiceSoapBinding" type="ns1:IHelloWS">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="getName">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="getName">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="getNameResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="getUserList">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="getUserList">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="getUserListResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="getUser">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="getUser">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="getUserResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="getUserMap">
  <soap:operation soapAction="" style="document" /> 
- <wsdl:input name="getUserMap">
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output name="getUserMapResponse">
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="HelloWSImplService">
- <wsdl:port binding="tns:HelloWSImplServiceSoapBinding" name="HelloWSImplPort">
  <soap:address location="http://localhost:8181/blog/webservice/hello" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

 

参考资料:

WebService报错:org.apache.cxf.interceptor.Fault: No such operation

五、CXF WebService整合Spring

 

posted @ 2015-06-02 09:42  snow__wolf  阅读(2205)  评论(0)    收藏  举报