---
title: "配置Xfire+Spring+Ibatis心得(续)"
author: "rocye"
date: "2009-02-17T09:56:56Z"
tags: []
categories: ["企业架构"]
slug: "xfire-spring-ibatis"
draft: false
lastmod: "2009-02-17T09:56:56Z"
id: 333936
url: "https://rocye.iteye.com/blog/333936"
---

因为这篇文章有点长，发现被截掉一部分，在这里进行补全，不知道怎么分页:

 

接下来就需要进行相关配置文件的编写了;

 

&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;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.xsd"&gt;

       &lt;import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /&gt;

 

       &lt;bean id="webAnnotations" class="org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations" /&gt;

①该Bean获取Spring容器中所有标注@WebService的Bean

       &lt;bean id="jsr181HandlerMapping" class="org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping"&gt;

              &lt;property name="xfire" ref="xfire" /&gt;

              &lt;property name="webAnnotations" ref="webAnnotations" /&gt;

       &lt;/bean&gt;

②对标注@WebService的Bean进行处理，完成导出工作

&lt;/beans&gt;

其实这个配置文件同Spring-config.xml，所以可而知，导入的地方和Spring-config.xml相同即可。

 

5．去掉了ActionServlet肯定要添加XfireServlet到项目中来了：

&lt;!-- XFire Servlet with Spring config --&gt;

  &lt;servlet&gt;

    &lt;servlet-name&gt;xfireServlet&lt;/servlet-name&gt;

    &lt;servlet-class&gt;org.codehaus.xfire.spring.XFireSpringServlet&lt;/servlet-class&gt;

  &lt;/servlet&gt;

  &lt;servlet-mapping&gt;

    &lt;servlet-name&gt;xfireServlet&lt;/servlet-name&gt;

    &lt;url-pattern&gt;/services/\*&lt;/url-pattern&gt;

  &lt;/servlet-mapping&gt;

这里的&lt;url-pattern&gt;/services/\*&lt;/url-pattern&gt; 需要注意，是发布的路路，最好是按这样写，对JSR 181方式更是如此，启动时会在控制台看到Mapping to /services/MsgUnitService 之类的字样，当时我为这个找过好多资料，想知道这个路径详细的配置，但是时间问题还没找到答案。到这里可以启动项目了，但是会有一个错，意思是说，不能将handler MsgUnitService Mapping to /services/MsgUnitService ，是因为已经mapped。因为这个错，找了好长时间的资料，最后发现，原来，JSR 181的这种标注方式，它会再一次解析类文件的业务层配置结构，也就是说，像Spring-config.xml中的这种dao类，dao接口，业务类，业务接口注册的式出现了两次，如果用JSR 181 方式进行配置应该连Spring-config.xml中业务层的配置部分也可以删除，但是其中的TransactionProxyFactoryBean怎么办呢，肯定不能删除的，才发现也有标注式的事务配置@Transaction 。因为这里没有采用这种业配置方式，所以JSR 181 式就先放下，最后用导出器的方式进行测试。

 

对就在的Xfire的配置文件写法改成

&lt;?xml version="1.0" encoding="UTF-8"?&gt;

      

       &lt;import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /&gt;

       &lt;bean id="MsgunitService" class="org.codehaus.xfire.spring.remoting.XFireExporter"&gt;

              &lt;property name="serviceFactory" ref="xfire.serviceFactory" /&gt;

              &lt;property name="xfire" ref="xfire" /&gt;

              &lt;property name="serviceBean" ref="msgunitServiceProxy" /&gt;

              &lt;property name="serviceClass" value="org.sh.spiss.eme.msgunit.MsgunitService" /&gt;

              &lt;property name="name" value="MsgunitServiceUT"/&gt;

       &lt;/bean&gt;

这样一来，本项目之前的Spring-config.xml的配置均可保留重用了。

 

6．重启服务器，访问[http://localhost/services/MsgunitServiceUT?wsdl](http://localhost/services/MsgunitServiceUT?wsdl) 这个地址就能得到相应的wsdl描述了。服务器端已通，不过今后会将事务改成标注方式后仍采用JSR 181的方式进行测试，毕竟那种方式更为简单方便。

 

7．客户端采用Flex完成测试，主要组件代码为：

&lt;mx:WebService id="webService" wsdl="http://localhost/services/MsgunitServiceUT?wsdl" showBusyCursor="true" useProxy="false"&gt;

    &lt;mx:operation name="getMsgunitXml" result="getMsgunitXml\_result(event);" fault="getMsgunitXml\_fault(event);" &gt;

    &lt;/mx:operation&gt;

    &lt;mx:operation name="getMsgunitXmlByPara" result="getMsgunitXml\_result(event);" fault="getMsgunitXml\_fault(event);" &gt;

    &lt;mx:request xmlns=""&gt;

            &lt;xmlstr&gt;

                   1234

            &lt;/xmlstr&gt;

    &lt;/mx:request&gt;

    &lt;/mx:operation&gt;

&lt;/mx:WebService&gt;

第一个操作方法，测试通过，正常请求，也能返回对应的字串，但是到这里就碰到问题，不知道为什么，请求带参数的webservice导出的方法时就好像根本找不到对应的方法一样，没有任何反应，参数传递方式找过很多资料，都是说采用上述写法，其中&lt;xmlstr&gt;这个名字要和服务器端所调用的方法参数名一致。但是还是不行，正在研究中，正在寻找原因中….

待续…

本文单纯属配置笔记，有很多地方说的很模糊。