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

Web框架
struts2(三)
struts2(四)
struts2(五)
struts2(六)
Spring中注入概念的简单介绍
深入探讨struts的ActionMessages消息机制(转)
DWR 的 Converter 实现原理简单分析及应用
详解Spring中bean的作用域
AJAX实现级联下拉框
Spring AOP面向方面编程原理:AOP概念
Spring结合Hibernate声明式事务配置
Struts 概述
Ajax 入门简介
Struts配置文件详解
Struts in Spring
Struts 开发的最佳实践
Struts核心标签
开发框架:利用STRUTS实现国际化支持
Struts自定义标签的过程
Struts 框架的基本概念及实现MVC模式的原理

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


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