微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webservice与spring的集成

在web项目中做webservice与spring的集成,整理如下:


  第一步:首先搭建spring环境;

                1;在web.xml中的配置:

                 

  <!-- 配置spring的配置文件的加载位置 -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!-- 配置spring的监听器 -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

              2;在项目的根目录下,记得创建applicationContext.xml的配置文件


第二步:spring 与webservice的集成

         

                1;在web.xml中的配置

                  

  <!-- 配置cxf -->
  <servlet>
  	<servlet-name>hello</servlet-name>
  	<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  	<load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
  	<servlet-name>hello</servlet-name>
  	<url-pattern>/WS/*</url-pattern>
  </servlet-mapping>

                2;接着在applicationContext.xml中配置cxf

               

              

<?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-3.0.xsd
	    http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
		http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
		
		<!-- 导入cxf的配置文件 -->
		<import resource="classpath:meta-inf/cxf/cxf.xml" />
		<import resource="classpath:meta-inf/cxf/cxf-extension-soap.xml" />

              3;就是如何发布 和 如何消费接口;

                   在服务器端,在applicationContext.xml中配置:

                 

		<!-- 对外发布接口 -->
		<jaxws:server id="iserver" address="/iserver" serviceClass="cn.suaee.WebServiceImpl" >
		</jaxws:server>

                   在客户端,在applicationContext.xml中的配置:

                                 

		<!-- 创建客户端调用服务端的对象 -->
		<jaxws:client id="iclient" address="http://localhost:8080/web-s/WS/iserver" serviceClass="cn.suaee.IWebService">
		</jaxws:client>
马马虎虎就这样总结一下吧!不吝赐教! 具体代码,可以在这里下载哦!http://download.csdn.net/detail/u011079727/8150039

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐