现在的位置: 首页 > 综合 > 正文

Spring与Metro(jaxws)整合

2018年05月22日 ⁄ 综合 ⁄ 共 1964字 ⁄ 字号 评论关闭

Spring与Metro整合  

2010-09-11 18:24:33|  分类:

web service
|  标签:
|举报
|字号 订阅

 整合时需要需要添加两个包jaxws-spring-1.8.jar和xbean-spring-3.5.jar,这里用的包的版本是1.8和3.5的。
xbean-spring-3.5.jar
下载地址:http://ftp.cica.es/mirrors/maven2/org/apache/xbean/xbean-spring/3.5/

jaxws-spring-1.8.jar
下载地址:http://download.java.net/maven/2/org/jvnet/jax-ws-commons/spring/jaxws-spring/1.8/

这种配置形式不需要sun-jaxws.xml。
第一步:当要发布一个web service时,首先需要修改web.xml,修改如下:

<web-app>
  <!-- this is for Spring -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- these are for JAX-WS -->
  <servlet>
    <servlet-name>jaxws-servlet</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>jaxws-servlet</servlet-name>
    <url-pattern>/add</url-pattern>
  </servlet-mapping>
  ... if you deploy more services,
  you might need more <servlet-mapping>s ...
</web-app>

第二步:修改applicationContext.xml,修改如下(红色的为要添加的部分):
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:ws="http://jax-ws.dev.java.net/spring/core"
  xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
  xsi:schemaLocation="

http://www.springframework.org/schema/beans


http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

    http://jax-ws.dev.java.net/spring/core

http://jax-ws.dev.java.net/spring/core.xsd


http://jax-ws.dev.java.net/spring/servlet

    http://jax-ws.dev.java.net/spring/servlet.xsd">

  <wss:binding url="/add" service="#addService" /> <!-- 这里的URL要与web.xml中url-pattern所指的URL一致 -->
  <wss:binding url="/sub">
    <wss:service><!-- nested bean is of course fine -->
      <ws:service bean="#myService" />
    </wss:service>
  </wss:binding>

  <!-- this bean implements web service methods -->
  <bean id="myService" class="foo.MyService" />

  <!-- simplest definition only needs the class name -->
  <ws:service id="addService" impl="foo.MyAddService" handlers="#myHandler"/>

  <bean id="myHandler" class="foo.MyHandler" />

</beans>

注:1、 wss:binding定义web service所要绑定的URL,ws:service定义web服务

抱歉!评论已关闭.