CXF整合Spring 1
一、创建一个工程,添加如下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
<?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>
package cxf.spring.service;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface HelloWorld {public String sayhello(@WebParam(name="name")String name);}
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;}}
<?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.xsdhttp://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" /><jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" /></beans>