xfire + sping 整合webservice

本文介绍如何使用XFire搭建Web服务及客户端,包括项目创建、服务定义与实现、配置文件设置等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

服务器端:

1、建立一个新的项目springXfireWebService (客户端)

2、在官网http://xfire.codehaus.org/Download中下载:xfire-distribution-1.2.6.zip (在建立项目后将所有jar包放到lib包中,测试删掉几个发现不行,似乎都是需要的,忘高手指明不足)和xfire-all-1.2.6.jar

3、建立webService:

package com.ebiz.xfire.service; import java.util.List; import com.ebiz.xfire.domain.CscProject; /** * @author Wu,Yang */ public interface CscWebService { /** *@author Wu, Yang *@desc "加载项目库数据" *@date 2009-09-28 */ List<CscProject> getCscProjectList(CscProject t); }

4、实现:

package com.ebiz.xfire.service.impl; import com.ebiz.xfire.service.WyWebService; /** * @author Wu,Yang */ public class WyWebServiceImpl implements WyWebService { public void printHello() { System.out.println("Hello!"); } }

5、引入jar包:xfire-distribution-1.2.6.zip 里面的包、xfire-all-1.2.6.jar和spring-2.5.6.jar。

6、与spring整合spring-context.xml:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName"> <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /> <!-- ====================testSpringXfire================= --> <bean id="wyWebServiceImpl" class="com.ebiz.xfire.service.impl.WyWebServiceImpl" /> <bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler" /> <bean name="webService" class="org.codehaus.xfire.spring.ServiceBean"> <property name="serviceBean" ref="wyWebServiceImpl"></property> <property name="serviceClass" value="com.ebiz.xfire.service.WyWebService"></property> <property name="inHandlers"> <list> <ref bean="addressingHandler" /> </list> </property> </bean> </beans>

7、配置web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" 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"> <display-name>XFireTest</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-context.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>

8、启动项目springXfireWebService (客户端),没有出错 第一步OK啦!!

客户端:

1、建立新的项目springXfireClient(客户端)

2、建立service:

package com.ebiz.xfire.service; /** * @author Wu,Yang * @version 2009-09-28 */ public interface WyWebService { /** *@desc "打印Hello" */ void printHello(); }

注意:这里的包的目录结构一定要和客户端的包的结构一定要一样(本人吃过亏的~~~~(>_<)~~~~ )

3、建立test.java

package com.testxfire.client; import java.net.MalformedURLException; import org.codehaus.xfire.XFireFactory; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; import com.ebiz.xfire.service.WyWebService; public class Test { public static void main(String[] args) { Service serviceModel = new ObjectServiceFactory().create(WyWebService.class); XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire()); String url = "http://localhost:8080/springXfireWebService/services/WyWebService"; try { WyWebService cws = (WyWebService) factory.create(serviceModel, url); cws.printHello(); } catch (MalformedURLException e) { e.printStackTrace(); } } }

4、在控制台出现:

Hello

完成。注意这里没有涉及到与数据库的交互,可以在实现中完善,另外在在spirng中配置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值