Flex 与 spring mvc 整合 BlazeDB

2015/08/04 10:15
阅读数 1.6K

本文主要学习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/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
           http://www.springframework.org/schema/flex 
           http://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.jar 
cfgatewayadapter.jar 
cglib-nodep-2.1_3.jar 
commons-codec-1.3.jar 
commons-httpclient-3.0.1.jar 
commons-logging.jar 
concurrent.jar 
flex-messaging-common.jar 
flex-messaging-core.jar 
flex-messaging-opt.jar 
flex-messaging-proxy.jar 
flex-messaging-remoting.jar 
jackson-lgpl-0.9.5.jar 
org.springframework.flex-1.0.0.RC1.jar 
spring2.5.6.jar 
spring-webmvc.jar 
xalan.jar 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部