Spring官方已经出来Spring 与 BlazeDS 集成的解决方案

来源:互联网 发布:mac .ssh目录在哪 编辑:程序博客网 时间:2024/05/21 09:04
 下载PDF向导:
http://static.springsource.org/spring-flex/docs/1.0.x/reference/pdf/spring-flex-reference.pdf
在线查看地址:
http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/index.html

废话就不说了,flex与spring集成的核心思想就是让spring来管理 MessageBroker
我这里主要讲如何配置:
先决条件:BlazeDS,spring2.5.6.jar, spring-webmvc.jar

配置过程:
(1)web.xml
<!-- flex config start --><listener><listener-class>flex.messaging.HttpFlexSession</listener-class></listener><!-- Flex默认配置<servlet><servlet-name>MessageBrokerServlet</servlet-name><display-name>MessageBrokerServlet</display-name><servlet-class>flex.messaging.MessageBrokerServlet</servlet-class><init-param><param-name>services.configuration.file</param-name><param-value>/WEB-INF/flex/services-config.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>MessageBrokerServlet</servlet-name><url-pattern>/messagebroker/*</url-pattern></servlet-mapping>--><!-- 采用Spring+Flex集成lib整合 org.springframework.flex-1.0.3.RELEASE.jar --><servlet> <servlet-name>flex_spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>flex_spring</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping> <!-- flex config end --><!-- spring config start  --><listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:config/spring/**/application*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- spring config end -->



(2)在WEB-INF下创建flex_spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?><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/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd"></beans>

我是根据运行时的错误提示建立的这个文件,如果你的项目不报错可以不建哈哈。。。

(3)修改remoting-config.xml

<?xml version="1.0" encoding="UTF-8"?><service id="remoting-service-commmon" 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>


(4)修改spring的配置文件

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:flex="http://www.springframework.org/schema/flex"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd         http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-2.5.xsd        http://www.springframework.org/schema/flexhttp://www.springframework.org/schema/flex/spring-flex-1.0.xsd"><!-- start*******************Integrate with flex and Spring*********************** --><bean id="_messageBroker"           class="org.springframework.flex.core.MessageBrokerFactoryBean">           <property name="servicesConfigPath">               <value>/WEB-INF/flex/services-config.xml</value>           </property>       </bean>       <bean           class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">           <property name="mappings">               <value>/*=_messageBroker</value>           </property>       </bean>       <bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter" />  <!-- end*******************Integrate with flex and Spring*********************** --><bean id="systemLogin" parent="TransactionProxyTemplate"><property name="target"><bean class="com.platform.sysBaseInfo.service.authority.imp.SystemLoginImp"></bean></property><flex:remoting-destination /></bean></beans>




******************************************************
将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>


文章参考地址:http://aguu125.iteye.com/blog/527970

 

原创粉丝点击