Flex、Spring整合:Spring BlazeDS Integration

准备:
1、下载Spring BlazeDS Integration: http://www.springsource.org/spring-flex
2、将下载回来的jar放置到我们之前创建的blazeds项目 http://depravedangel.iteye.com/blog/871480lib下

整合:
1、将原来flex提供的MessageBroker
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>

替换成Spring MVC 控制
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<servlet-mapping>
		<url-pattern>/spring/*</url-pattern>
	</servlet-mapping>


2、将blazeds/WEB-INF/flex/services-config.xml中
		<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
			<endpoint
				url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
				class="flex.messaging.endpoints.AMFEndpoint" />
		</channel-definition> -->

替换成Spring的url,交由spring过滤
	
		<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
			<endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf"
			class="flex.messaging.endpoints.AMFEndpoint"/>
			<properties>
				<polling-enabled>false</polling-enabled>
			</properties>
		</channel-definition>


3、打开applicationContext.xml,添加如下bean:
<!-- Maps request paths at /* to the BlazeDS MessageBroker -->
	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<value>/*=springManagedMessageBroker</value>
		</property>
	</bean>
	
	<!-- Dispatches requests mapped to a MessageBroker -->
	<bean class="org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter" />
	
	<!-- Bootstraps and exposes the BlazeDS MessageBroker -->
	<bean id="springManagedMessageBroker" class="org.springframework.flex.messaging.MessageBrokerFactoryBean" />


4、打开services-config.xml,删除我们自己配置的SpringFactory
<factories>
		<factory id="spring" class="com.sky.flexonspring.factories.SpringFactory" />
	</factories>

现在已经由SBI帮我们处理了,不再需要我们再去关心了

5、打开remoting-config.xml文件,删除如下代码:
<destination id="guestListService">
		<properties>
			<factory>spring</factory>
			<source>guestListService</source>
		</properties>
	</destination>

整合SBI后,remoting-config.XML不再需要配置了,改成在applicationContent.xml中添加如下配置:

<!-- Expose the guestListService bean for BlazeDS remoting -->
	<bean id="guestService" class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
		<property name="messageBroker" ref="springManagedMessageBroker"/>
		<property name="service" ref="guestListService"/>
	</bean>


6、最后一步,修改前台Flex程序的remoteObject对象属性,使其指向spring的url,便于spring过滤转发
<mx:RemoteObject id="ro"
					 destination="guestService"
					 endpoint="http://localhost:8080/blazeds/spring/messagebroker/amf"

你可能感兴趣的:(java,spring,xml,bean,Flex)