一、创建一个工程,添加如下jar包
cxf-2.5.1.jar
wsdl4j-1.6.2.jar
xmlschema-core-2.0.1.jar
jetty-server-7.5.3.v20111011.jar
jetty-util-7.5.3.v20111011.jar
jetty-continuation-7.5.3.v20111011.jar
jetty-http-7.5.3.v20111011.jar
jetty-io-7.5.3.v20111011.jar
neethi-3.0.1.jar
另外再添加发布包中与spring有关的jar
二、服务器端
1、web.xml
2、接口类
3、实现类
4、bean.xml
5、启动tomcat并发布
cxf-2.5.1.jar
wsdl4j-1.6.2.jar
xmlschema-core-2.0.1.jar
jetty-server-7.5.3.v20111011.jar
jetty-util-7.5.3.v20111011.jar
jetty-continuation-7.5.3.v20111011.jar
jetty-http-7.5.3.v20111011.jar
jetty-io-7.5.3.v20111011.jar
neethi-3.0.1.jar
另外再添加发布包中与spring有关的jar
二、服务器端
1、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>cxf-first</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:*bean.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/cxftest/*</url-pattern>
</servlet-mapping>
</web-app>
2、接口类
package cxf.spring.service;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayhello(@WebParam(name="name")String name);
}
3、实现类
package cxf.spring.service;
import javax.jws.WebService;
@WebService(endpointInterface="cxf.spring.service.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayhello(String name) {
return "Hello,"+name;
}
}
4、bean.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: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/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" />
<bean id="hello" class="cxf.spring.service.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />
</beans>
5、启动tomcat并发布