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

Web框架
Web框架:addOptions and removeAllOptions
Web框架:Xfire与Spring集成那些事
Web框架:多个dwr.xml配置方法
Web框架:小编整理Hibernate 基本查詢
Web框架:DWR使用中的web.xml配置
Web框架:Struts2使用Spring插件完成整合
Web框架:小编叙Spring的事务管理
Web框架:Struts2国际化实现用户自行选择语言
Web框架:Struts2中加载资源文件的方式
Web框架:Struts2中整合图表工具JFreeChart的时间顺序图
Web框架:浅谈Struts2的内建校验器
Web框架:FreeMarker中的escape , noescape指令
Struts2的Visitor校验器
Struts2中的subset标签使用方法浅谈
Hibernate核心接口那些事
Spring中的依赖注入
Spring中的Inversion of Control 容器
浅析Spring中的单元测试
用StrutsTestCase测试Struts应用程序
浅谈Struts中html:options的使用

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


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