版本:Spring3.2.2
CXF2.7.2
1.导入jar包
CXF的jar包
spring的jar包
2.配置web.xml,在web.xml中加入一下内容
<!-- 加载Spring容器配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 设置Spring容器加载配置文件路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:cxf.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> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>3.配置cxf.xml,在src目录下新建cxf.xml,内容如下
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" 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://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.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="HelloWorld" implementor="cn.cxf.impl.HelloWorldImpl" address="/hello"> </jaxws:endpoint> </beans>
package cn.cxf; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHi(String name); }
package cn.cxf.impl; import javax.jws.WebService; import cn.cxf.HelloWorld; @WebService(endpointInterface="cn.cxf.helloWorld",serviceName="HelloWorldImpl") public class HelloWorldImpl implements HelloWorld { @Override public String sayHi(String name) { // TODO Auto-generated method stub return "i am superman"; } }
原文:http://blog.csdn.net/yellowhdh/article/details/19754069