加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice与spring的集成

发布时间:2020-12-16 23:13:48 所属栏目:安全 来源:网络整理
导读:在web项目中做webservice与spring的集成,整理如下: ? 第一步:首先搭建spring环境; ??????????????? 1;在web.xml中的配置: ????????????????? !-- 配置spring的配置文件的加载位置 -- context-param param-namecontextConfigLocation/param-name param-

在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读