首页 > 其他 > 详细

Spring+CXF整合

时间:2014-02-24 01:40:31      阅读:357      评论:0      收藏:0      [点我收藏+]

版本:Spring3.2.2

            CXF2.7.2

1.导入jar包

bubuko.com,布布扣bubuko.com,布布扣CXF的jar包

bubuko.com,布布扣

spring的jar包

bubuko.com,布布扣

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>   

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,若成功则有以下内容

bubuko.com,布布扣


Spring+CXF整合

原文:http://blog.csdn.net/yellowhdh/article/details/19754069

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!