Flex 与 Spring 集成

xiaoxiao2026-08-17  23

Flex 与 Spring 集成 参考文档是 Spring BlazeDS Integration Reference Guide。spring已经提供了与flex的集成的支持,主要的jar包下载地址:http://www.springsource.com/download/community?project=Spring%20BlazeDS%20Integration Flex与Spring集成的核心思想就是让Spring来管理 MessageBroker。如何集成?可以总结为三步。 1、首先,修改 web.xml文件,将之前配置的 MessageBrokerServlet 去掉改成spring的, <servlet> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/config/web-application-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>/messagebroker/*</url-pattern></servlet-mapping> 2,新建文件 web-application-config.xml <?xml version="1.0" encoding="GB2312" ?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/flexhttp://www.springframework.org/schema/flex/spring-flex-1.0.xsd"><!-- Bootstraps and exposes the BlazeDS MessageBroker simplest form --><flex:message-broker id="_messageBroker" services-config-path="/WEB-INF/flex/services-config.xml"> <flex:mapping pattern="/messagebroker/*" /> <flex:exception-translator ref="myExceptionTranslator" /></flex:message-broker><!--上面配置是一种简单配置,另外一种更简单配置为:<flex:message-broker/>还有一种配置为:<bean id="mySpringManagedMessageBroker" class="org.springframework.flex.core.MessageBrokerFactoryBean"> <property name="servicesConfigPath" value="classpath*:flex/services-config.xml" /></bean>--><!-- Maps request paths at /* to the BlazeDS MessageBroker --><bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value> /*=_messageBroker </value> </property></bean><!-- 下面这个Adapter似乎不用配置,因为我注释后照样可以使用 --><!--Dispatches requests mapped to a MessageBroker <bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter" />--></beans> 3,写remoting-config.xml 文件: <?xml version="1.0" encoding="UTF-8"?><service id="remoting-service" class="flex.messaging.services.RemotingService"><adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/></adapters><default-channels> <channel ref="my-amf"/></default-channels></service> 到目前为止,flex已经跟spring集成到一起了。 4、将spring的bean导出为flex的Destination。我们要在web-application-config.xml文件中增加。 有三种方式: 第一种: <bean id="productService" class="flex.samples.product.ProductServiceImpl" /><flex:remoting-destination ref="productService" /> 第二种: <bean id="productService" class="flex.samples.product.ProductServiceImpl" > <flex:remoting-destination /></bean> 第三种: <bean id="product" class="org.springframework.flex.remoting.RemotingDestinationExporter"> <property name="messageBroker" ref="_messageBroker"/> <property name="service" ref="productService"/> <property name="serviceId" value="productService"/> <property name="includeMethods" value="read, update"/> <property name="excludeMethods" value="create, delete"/> <property name="channels" value="my-amf, my-secure-amf"/></bean> 附件是一个例子工程,没有提供jar,工程中所需要的jar backport-util-concurrent.jarcfgatewayadapter.jarcglib-nodep-2.1_3.jarcommons-codec-1.3.jarcommons-httpclient-3.0.1.jarcommons-logging.jarconcurrent.jarflex-messaging-common.jarflex-messaging-core.jarflex-messaging-opt.jarflex-messaging-proxy.jarflex-messaging-remoting.jarjackson-lgpl-0.9.5.jarorg.springframework.flex-1.0.0.RC1.jarspring2.5.6.jarspring-webmvc.jarxalan.jar 本文来源于 冰山上的播客 http://xinsync.xju.edu.cn , 原文地址:http://xinsync.xju.edu.cn/index.php/archives/5078 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-5051355.html

最新回复(0)