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

Web框架
浅谈Ajax与Spring集成
浅谈Mock和基于Spring容器管理事务的测试
Hibernate中一级缓存与二级缓存
浅谈Hibernate的配置信息(一)
浅谈Hibernate的配置信息(二)
浅谈Spring中使用Quartz来执行计划任务
浅谈JFreeChart实时曲线(代码)
Ajax框架中选DWR还是A4J
浅谈Hibernate中关联问题
浅谈项目开发过程中使用Struts-menu
浅谈使用模板模式简化操作Hibernate
Hibernate中加载并存储对象
浅谈Hibernate依赖对象(Dependent objects)
浅谈Hibernate中自定义值类型
ORM那些事
51培训对Hibernate中的事务详解
51培训详谈Hibernate检索
详谈Struts2的核心概念(上)
详谈Struts2的核心概念(下)
浅谈应用dom4j操作xml文件

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 473 ::
收藏到网摘: 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"/>