Spring Flex结合

一、下载BlazeDS,解压后放到工程中。

二、工程中加入Srping和spring-flex的包org.springframework.flex-1.0.3.RELEASE.jar。如果BlazeDS的版本是4.0,spring-flex包的版本不能太高,否则启动时会报错。

三、修改web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

    <display-name>BlazeDS</display-name>
    <description>BlazeDS Application</description>

    <!-- Spring配置文件,用于配置spring和其它框架结合 -->
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
          /WEB-INF/config/applicationContext.xml
      </param-value>
    </context-param>

	<listener> 
	    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
	</listener>

    <!-- Http Flex Session attribute and binding listener support -->
    <listener>
        <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>
    
    <servlet>  
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
	        <init-param>
                    <!-- 给flex单独用一个spring配置文件 -->
	            <param-name>contextConfigLocation</param-name>  
	            <param-value>/WEB-INF/config/flex-application-config.xml</param-value>  
	        </init-param>
        <load-on-startup>1</load-on-startup>  
    </servlet>  

<!-- RDS服务,只在Flash Builderw的数据服务中使用,使用数据服务可以自动生成访问Java中的服务类以及数据对象 -->
<!-- begin rds -->
    <servlet>
        <servlet-name>RDSDispatchServlet</servlet-name>
		<display-name>RDSDispatchServlet</display-name>
        <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
		<init-param>
			<param-name>useAppserverSecurity</param-name>
			<param-value>false</param-value>
		</init-param>
        <init-param>
            <param-name>messageBrokerId</param-name>
            <param-value>_messageBroker</param-value>
        </init-param>
        <load-on-startup>10</load-on-startup>
    </servlet>
<!-- end rds -->

    <!-- Map /spring/* requests to the DispatcherServlet -->  
    <servlet-mapping>  
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>  
        <url-pattern>/messagebroker/*</url-pattern>  
    </servlet-mapping> 

    <servlet-mapping id="RDS_DISPATCH_MAPPING">
        <servlet-name>RDSDispatchServlet</servlet-name>
        <url-pattern>/CFIDE/main/ide.cfm</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <!-- for WebSphere deployment, please uncomment -->
    <!--
    <resource-ref>
        <description>Flex Messaging WorkManager</description>
        <res-ref-name>wm/MessagingWorkManager</res-ref-name>
        <res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    -->

</web-app>

 

 

<?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:flex="http://www.springframework.org/schema/flex"
	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">

	<bean id="_messageBroker"  
        class="org.springframework.flex.core.MessageBrokerFactoryBean">  
        <!-- <property name="servicesConfigPath">  
            <value>/WEB-INF/flex/services-config.xml</value>  
        </property> -->
    </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>  
  
    <!-- Dispatches requests mapped to a MessageBroker -->  
    <bean  
        class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter" />

    <bean id="rscLayersCfgAction" class="com.linkage.app.action.RscLayersCfgAction">
        <property name="service" ref="rscLayersCfgService"></property>
    </bean>
    <bean id="rscGridMsgAction" class="com.linkage.app.action.RscGridMsgAction">
        <property name="service" ref="rscGridMsgService"></property>
    </bean>

	<!-- 配置对flex远程调用开放的类和方法 -->
    <flex:remoting-destination ref="rscLayersCfgAction" include-methods="getRscLayersCfgs"/>
    <flex:remoting-destination ref="rscGridMsgAction" include-methods="addRscGridMsg"/>
</beans>

你可能感兴趣的:(spring)