在一个ss2h的项目中配置xfire的心得

花了近一周的时间,终于在项目中配置好了xfire

项目是spring2+struts2+hibernate3的项目,现在由于要和其他系统接口,需要webservice,在网上查了些资料,相比较之下,还是觉得xfire比较方便,配置起来也不麻烦。

         于是就决定用xfire,最先遇到的问题是包的问题,不知道该加什么包,最后没有办法,只有在myeclipse中建立一个webserviceweb项目,加了xfire的包。让后在到xfirebin目录和modules目录下面对照这myeclipse中的包一个个的选出来,加到项目里面去。

让后就按照网上那些大虾所介绍的方法,一步一步的写配置文件。

我试了很多种方法,但是还是错的。让我有些郁闷。

后来看到一位仁兄说要去掉spring-1.2.6.jar这个包,因为项目是用的spring2的包,和xfire配置在一起会有冲突。于是我就将spring-1.2.6.jar删除了。但是还是出错。

试了很多方法终于成功了,现在写下来,做个记录,加深一下记忆。

 

第一步:加xfire的包,

第二步:在web.xml中配置xfire

 

ContractedBlock.gif ExpandedBlockStart.gif Code
……

         
<context-param>

                   
<param-name>contextConfigLocation</param-name>

                   
<param-value>

                            classpath:applicationContext-common-business.xml,

                            classpath:applicationContext-common-webservice.xml

                   
</param-value>

         
</context-param>

……

<!—这个和spring的配置一样-->

         
<listener>

                   
<listener-class>

                            org.springframework.web.context.ContextLoaderListener

                   
</listener-class>

         
</listener>

……

<!-- XFire配置begin -->

      
<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>

 

      
<!-- XFire配置end -->

……

 

这里的 applicationContext-common-business.xml spring注入所需要的类,里面的spring配置如下

        

ContractedBlock.gif ExpandedBlockStart.gif Code
 <!-- Webservice取得数据报表-->

   
<bean name="reportService" parent="baseProxy">

                   
<property name="target"><ref bean="reportServiceImpl" /></property>

   
</bean>

   
<bean name="reportServiceImpl" class="com.lemsun.jtreport.service.audito.ReportServiceImpl" autowire="byName"/>

 

文件applicationContext-common-webservice.xml就是webservice的配置文件了。

 

完整的配置文件如下。这里ref="reportServiceImpl"reportServiceImpl已经在applicationContext-common-business.xml中已经配置了所以这里就直接引用就行了。name="Servicereport"中的Servicereport就是一个名字,并不是webservice的名字,

   

ContractedBlock.gif ExpandedBlockStart.gif Code
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

        
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>

   

    
<bean name="Servicereport" class="org.codehaus.xfire.spring.ServiceBean">

        
<property name="serviceBean" ref="reportServiceImpl"/>

        
<property name="serviceClass" value="com.lemsun.jtreport.service.audito.ReportService"/>

        
<property name="inHandlers">

            
<list>

                
<ref bean="addressingHandler"/>

            
</list>

        
</property>

    
</bean> 

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

</beans>

 

其实这个配置过程就这三个文件。走了不少弯路,但是也学了不少东西。

转载于:https://www.cnblogs.com/ConjurerYang/archive/2009/07/13/1522404.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值