Flex 與 spring mvc 整合 BlazeDB

本文主要學習Flex跟spring如何集成。參考文檔是 Spring BlazeDS Integration Reference Guide。spring已經提供了與flex的集成的支持,主要的jar包下載地址:http://www.springsource.com /download/community?project=Spring%20BlazeDS%20Integration 

flex與spring集成的核心思想就是讓spring來管理 MessageBroker。如何集成?能夠總結爲三步。 
一、首先,修改 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集成到一塊兒了。 
四、將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 java

相關文章
相關標籤/搜索