本文链接:http://blog.csdn.net/kongxx/article/details/7525481

Apache CXF实战之一 Hello World Web Service

书接上文,下面看看CXF怎样和spring集成。

1.创建HelloWorld 接口类

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;
  2. import javax.jws.WebMethod;
  3. import javax.jws.WebParam;
  4. import javax.jws.WebResult;
  5. import javax.jws.WebService;
  6. @WebService
  7. public interface HelloWorld {
  8. @WebMethod
  9. @WebResult String sayHi(@WebParam String text);
  10. }
package com.googlecode.garbagecan.cxfstudy.helloworld;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebResult;

import javax.jws.WebService; @WebService

public interface HelloWorld {

@WebMethod

@WebResult String sayHi(@WebParam String text);

}

2.创建HelloWorld实现类 

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;  
  2.   
  3. public class HelloWorldImpl implements HelloWorld {  
  4.   
  5.     public String sayHi(String name) {  
  6.         String msg = "Hello " + name + "!";  
  7.         return msg;  
  8.     }  
  9. }  
package com.googlecode.garbagecan.cxfstudy.helloworld;

public class HelloWorldImpl implements HelloWorld {
public String sayHi(String name) {
String msg = "Hello " + name + "!";
return msg;
}

}

3.修改web.xml文件

  1. <!DOCTYPE web-app PUBLIC  
  2.  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  
  3.  "http://java.sun.com/dtd/web-app_2_3.dtd" >  
  4.   
  5. <web-app>  
  6.   
  7.     <display-name>cxfstudy</display-name>  
  8.   
  9.     <servlet>  
  10.         <servlet-name>cxf</servlet-name>  
  11.         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
  12.         <load-on-startup>1</load-on-startup>  
  13.     </servlet>  
  14.   
  15.     <servlet-mapping>  
  16.         <servlet-name>cxf</servlet-name>  
  17.         <url-pattern>/ws/</url-pattern>  
  18.     </servlet-mapping>  
  19.   
  20.     <listener>  
  21.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  22.     </listener>  
  23.       
  24.     <context-param>  
  25.         <param-name>contextConfigLocation</param-name>  
  26.         <param-value>classpath
05-20 03:12