Spring 4.*和CXF3.*整合

之前寫過一個CXF整合spring,那是的CXF是2.2的,Spring是3.2的,前些日子去CXF官網下了個3.1的,用Spring4.3的整合,發現用舊版本配置的方式來配置新版的已不管用了,這兩天又在網上搜了CXF3.0和Spring4的整合方式,原來使用的包都變了,這又重新整理一份,真麻煩。


接口

[java] view plain copy
  1. package test;  
  2.   
  3.   
  4. import javax.jws.WebParam;  
  5. import javax.jws.WebService;  
  6.   
  7.   
  8. @WebService  
  9. public interface Hello {  
  10. public String say(@WebParam(name="name")String name);  
  11. }  

實現

[java] view plain copy
  1. package test;  
  2.   
  3. import javax.jws.WebService;  
  4.   
  5. @WebService(endpointInterface="test.Hello")  
  6. public class HelloImp implements Hello {  
  7.   
  8.     public String say(String name) {  
  9.         return "hello,"+name;  
  10.     }  
  11.   
  12. }  

bean.xml(或applicationContext.xml)

[java] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"   
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xmlns:context="http://www.springframework.org/schema/context"   
  5.        xmlns:jaxws="http://cxf.apache.org/jaxws"  
  6.        xsi:schemaLocation=" http://www.springframework.org/schema/beans    
  7.                             http://www.springframework.org/schema/beans/spring-beans.xsd   
  8.                             http://www.springframework.org/schema/context    
  9.                             http://www.springframework.org/schema/aop/spring-context.xsd  
  10.                             http://cxf.apache.org/jaxws   
  11.                             http://cxf.apache.org/schemas/jaxws.xsd">  
  12.     <import resource="classpath:META-INF/cxf/cxf.xml"/>  
  13.     <jaxws:endpoint id="abc" address="/cde" implementor="test.HelloImp"></jaxws:endpoint>  
  14.       
  15. </beans>  

web.xml

[java] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  3.          xmlns="http://xmlns.jcp.org/xml/ns/javaee"   
  4.          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee   
  5.                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"  
  6.          id="WebApp_ID"   
  7.          version="3.1">  
  8.   <display-name>test</display-name>  
  9.   <welcome-file-list>  
  10.     <welcome-file>index.html</welcome-file>  
  11.     <welcome-file>index.htm</welcome-file>  
  12.     <welcome-file>index.jsp</welcome-file>  
  13.     <welcome-file>default.html</welcome-file>  
  14.     <welcome-file>default.htm</welcome-file>  
  15.     <welcome-file>default.jsp</welcome-file>  
  16.   </welcome-file-list>  
  17.     
  18.   <servlet>  
  19.    <servlet-name>CXFServlet</servlet-name>  
  20.    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
  21.    <load-on-startup>1</load-on-startup>  
  22.   </servlet>  
  23.   <servlet-mapping>  
  24.    <servlet-name>CXFServlet</servlet-name>  
  25.    <url-pattern>/service/*</url-pattern>  
  26.   </servlet-mapping>  
  27.     
  28.   <listener>  
  29.    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  30.   </listener>  
  31.     
  32.   <context-param>  
  33.    <param-name>contextConfigLocation</param-name>  
  34.    <param-value>classpath:bean.xml</param-value>  
  35.   </context-param>  
  36.     
  37. </web-app>  


使用的包(缺一不可)



訪問URL:http://localhost:8080/test/service/cde?wsdl


生成客戶端命令:wsdl2java -client -p client -d e:/ http://localhost:8080/test/service/cde?wsdl

把生成的客戶端放入到項目裏,直接運行其中xxxxxxx_Client.Java類,即可看到運行結果。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章