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

Web框架
Web框架介绍---SpringMVC
基于Django框架的敏捷Web开发
驾驭新的Ruby Web框架Waves
JAVA脚本取得struts2 OgnlValueStack中的值
Struts中DownloadAction的使用
优化Hibernate性能的几点建议
Hibernate高级查询实战
对于Struts和Spring两种MVC框架的比较
JSF与Struts的比较 超易懂!
hibernate 主键生成方式
spring acegi 官方例子
获取ApplicationContext的几种方式
Spring与自动调度任务 基于Timer的任务调度器的应用
spring+hibernate 的包的详解,帮你了解每个包的作用以及是否必要导入工程
hibernate 一对一(one to one)级联保存
struts formbean 就是鸡肋
Struts中常用的几种Action
spring的应用事例
struts2(一)
struts2(二)

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


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