版本: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,内容如下
<?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: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> 4.编辑WebService接口类package cn.cxf; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHi(String name); }
5.编辑WebService实现类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"; } }6.启动Tomcat,在浏览器中输入地址http://localhost:8080/CXFSpring/hello?wsdl,若成功则有以下内容

本文详细介绍了如何在Spring框架中集成CXF来实现Web服务,包括导入jar包、配置web.xml、配置cxf.xml、编辑WebService接口类与实现类、启动Tomcat并验证服务。
3915

被折叠的 条评论
为什么被折叠?



