如何使用Spring+Xfire构建WebService?
(1)编写发布接口ITrainTimeServiceRemote
(2)编写实现类TrainTimeServiceImpl
(3)编写发布配置文件application-webservice.xml
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<bean id="baseWebService"
class="org.codehaus.xfire.spring.remoting.XFireExporter"
lazy-init="false" abstract="true">
<property name="serviceFactory" ref="xfire.serviceFactory" />
<property name="xfire" ref="xfire" />
</bean>
<bean id="traintimeService" parent="baseWebService">
<property name="serviceBean" ref="traintimeService_implement" />
<property name="serviceClass"
value="com.bjjdsy.ky.zl.service.ITrainTimeServiceRemote" />
</bean>
<bean id="traintimeService_implement"
class="com.bjjdsy.ky.zl.service.TrainTimeServiceImpl">
<property name="traintimeDao">
<ref bean="TrainTimeDAO" />
</property>
</bean>
(4)如果有方法返回复杂类型,则需要辨析配置文件,未知和接口文件放在同一包下
ITrainTimeServiceRemote.aegis.xml
<mappings>
<mapping>
<method name="getTrainTimeByTrainCode">
<return-type componentType="com.bjjdsy.ky.zl.domain.ZlTrainTimeTab"/>
</method>
</mapping>
</mappings>
(5)web.xml配置
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
调用:
<bean id="trainTimeService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean">
<property name="serviceClass">
<value>com.bjjdsy.ky.zl.service.ITrainTimeServiceRemote</alue>
</property>
<property name="wsdlDocumentUrl"> <value>http://10.100.2.12/KY_ZL_BASE/services/ITrainTimeServiceRemote?wsdl</value>
</property>
</bean>
此后,就可以当作本地的trainTimeService来使用接口方法了
本文地址:http://www.45fan.com/a/question/68013.html