您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> JAVA >> 辅导 >> 正文    
  Spring集成XFire开发WebService 【注册男护士专用博客】          

Spring集成XFire开发WebService

www.nanhushi.com     佚名   不详 

  Spring是目前最流行的JavaEE Framework,但是使用Spring的Spring-WS开发WebService却十分繁琐。XFire是一个简化WebService开发的开源项目,通过Spring和XFire的结合可以大大简化基于Spring Framework的应用中的WebService开发。

  Spring和XFire可以通过多种方式结合,下文介绍的是笔者常用的一种简单而实用的方法。所用的Spring版本为2.0,XFire版本为1.2.6。

  1、配置XFire Servlet

  在web.xml中加入如下配置:

<servlet>
<servlet-name>XFireServlet</servlet-name>
 <servlet-class>
  org.codehaus.xfire.spring.XFireSpringServlet
 </servlet-class>
</servlet>
<servlet-mapping>
 <servlet-name>XFireServlet</servlet-name>
 <url-pattern>/servlet/XFireServlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>XFireServlet</servlet-name>
 <url-pattern>/services/*</url-pattern>
</servlet-mapping>

  2 配置Spring的监听器,同基于spring的Web项目一样Spring的监听器是必不可少的。

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>
  classpath:org/codehaus/xfire/spring/xfire.xml,
  /WEB-INF/applicationContext.xml
 </param-value>
</context-param>
<listener>
 <listener-class>
  org.springframework.web.context.ContextLoaderListener
 </listener-class>
</listener>

  以下是完整的web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   classpath:org/codehaus/xfire/spring/xfire.xml,
   /WEB-INF/applicationContext.xml
  </param-value>
 </context-param>
<listener>
 <listener-class>
  org.springframework.web.context.ContextLoaderListener
 </listener-class>
</listener>
<servlet>
 <servlet-name>XFireServlet</servlet-name>
 <servlet-class>
  org.codehaus.xfire.spring.XFireSpringServlet
 </servlet-class>
</servlet>
<servlet-mapping>
 <servlet-name>XFireServlet</servlet-name>
 <url-pattern>/servlet/XFireServlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
 <servlet-name>XFireServlet</servlet-name>
 <url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>


  3 定义接口及实现服务

  定义接口,这个接口中定义要通过WebService暴露的方法

package org.ccsoft;

publicinterface HelloWS {
 public String sayHello(String sb);
}

  实现服务

package org.ccsoft;

publicclass HelloWSImp implements HelloWS {
 public String sayHello(String sb) {
  // TODO Auto-generated method stub
  return"Hello "+sb;
 }
}

  4 配置服务

  将上文中实现的服务,加入到spring的配置文件中。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="helloWS" class="org.ccsoft.HelloWSImp"/>
<bean name="helloService" class="org.codehaus.xfire.spring.ServiceBean">
<property name="serviceBean" ref="helloWS"/>
<property name="serviceClass" value="org.ccsoft.HelloWS"/>
<property name="inHandlers">
 <list>
  <ref bean="addressingHandler"/>
 </list>
</property>
</bean>

<bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler"/>
</beans>

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目

      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)                            【进男护士社区逛逛】
    姓 名:
    * 游客填写  ·注册用户 ·忘记密码
    主 页:

    评 分:
    1分 2分 3分 4分 5分
    评论内容:
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。