当前位置: 首页 > 图文教程 > Java技术 > Web框架 > Web框架:Xfire与Spring集成那些事

Web框架
Struts开发过程中的异常处理机制
ServletContext与ServletConfig分析
使用Ajax的挑战
Web程序从Struts向Stripes框架的移植
Shale不是Struts
Web框架:基于Ajax的应用程序架构汇总
Web框架:使用Ajax技术开发Web应用程序
Web框架:简单理解Hibernate三种状态的概念及互相转化
Web框架:浅谈Struts2中拦截器应用
Web框架:Struts2中的Action
Web框架:Struts2高级文件上传
Web框架:小编谈嵌入XFire服务介绍及实现
Web框架:DWR中signatures标签的使用
WEB框架:小编总结Struts2的经典输入校验
WEB框架:小编祥谈Struts2的数据标签中Action与Bean标签的使用
Web框架:小议struts2类型转换
Web框架:小编浅谈Struts2的pub-sub事件模型
Web框架:小编简述JSF
Web框架:Hibernate事务管理
Web框架:Struts高级特性(StrutsAdvancedFeature)验证

Web框架:Xfire与Spring集成那些事


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 475 ::
收藏到网摘: n/a

Xfire很好的提供了对Spring的支持。你可以很方便的将一个Spring bean包装成一个Web Service。可以通过创建Spring管理的XFire engineServiceRegistryransportManager ServiceFactory来实现。

Xfire使用XBean(http://xbean.org)来管理配置文件。XBean允许在XML文档中混合Spring Bean的定义。

下面是一个简单的配置文件:

<beans xmlns="http://xfire.codehaus.org/config/1.0">

<service>

<name>Echo</name>

<serviceClass>org.codehaus.xfire.test.Echo</serviceClass>

</service>

</beans>

可以通过XBeanClasspath application context加载它:

import junit.framework.TestCase;

import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;

import org.codehaus.xfire.service.ServiceRegistry;

public class XBeanExampleTest

extends TestCase

{

public void testLoading()

throws Exception

{

ClassPathXmlApplicationContext context =

new ClassPathXmlApplicationContext(new String[] {

"/org/codehaus/xfire/spring/examples/simple.xml",

"/org/codehaus/xfire/spring/xfire.xml" });

ServiceRegistry reg = (ServiceRegistry) context.getBean("xfire.serviceRegistry");

assertTrue(reg.hasService("Echo"));

}

}

下面是一个混合Spring Bean的例子:

<beans xmlns="http://xfire.codehaus.org/config/1.0">

<service>

<name>Echo</name>

<serviceBean>#echoBean</serviceBean>

</service>

<bean id="echoBean" class="org.codehaus.xfire.services.Echo"/>

</beans>

service设置属性:

<service>

... define your normal attributes ...

<properties>

<property key="mtom-enabled">true</property>

<property key="myProperty">myValue</property>

<properties>

</service>

你可以完全通过Spring声明的方式定义服务,例如:

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

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

<property name="serviceClass" value="org.codehaus.xfire.test.Echo"/>

<property name="inHandlers">

<list>

<ref bean="addressingHandler"/>

</list>

</property>

</bean>

<bean id="echo" class="org.codehaus.xfire.test.EchoImpl"/>

<bean

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