JavaEE集成Flex4

Flex集成J2EE
Flex,Spring2.5或更高,BlazeDS

Spring BlazeDS Integration 是什么?
Spring BlazeDS Integration 是 SpringSource 的开源项目,用于整合 Spring 与 BlazeDS。

为什么需要 Spring BlazeDS Integration?
不使用 Spring BlazeDS Integration 同样可以整合 Spring 与 BlazeDS。但这种整合方式不自然,需要额外维护一个 BlazeDS 配置文件,Spring BlazeDS Integration 会改善这种处境。

Spring BlazeDS Integration 需要的软件环境:
Java 5 或更高
Spring 2.5.6 或更高
BlazeDS 3.2 或更高

Spring BlazeDS Integration 特征
MessageBroker(BlazeDS 的核心组件)被配置为 Spring 管理的 Bean
Flex 客户端发出的 HTTP 消息通过 Spring 的 DispatcherServlet 路由给 MessageBroker
Remote objects 以 Spring 的方式配置在 Spring 配置文件内


第一步
1 需要准备spring3.0 lib文件
org.springframework.aop-3.0.2.RELEASE.jar
org.springframework.asm-3.0.2.RELEASE.jar
org.springframework.beans-3.0.2.RELEASE.jar
org.springframework.context-3.0.2.RELEASE.jar
org.springframework.core-3.0.2.RELEASE.jar
org.springframework.expression-3.0.2.RELEASE.jar
org.springframework.web.servlet-3.0.2.RELEASE.jar
org.springframework.web-3.0.2.RELEASE.jar


2 准备spring依赖包
org.aopalliance 内的 com.springsource.org.aopalliance-1.0.0.jar
edu.emory.mathcs.backport 内的 com.springsource.edu.emory.mathcs.backport-3.0.0.jar
net.sourceforge.cglib 内的 com.springsource.net.sf.cglib-2.2.0.jar


3 Spring BlazeDS Integration(Spring对于BlazeDS的支持jar文件)
org.springframework.flex-1.0.3.RELEASE.jar


第二步
修改现有web项目中的web.xml文件结构
<servlet>
  <servlet-name>MyFlexApp</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/web-application-config.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>MyFlexApp</servlet-name>
  <url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>


第三步
配置 web-application-config.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/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/flex
       http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">

   <flex:message-broker />
</beans>


第四步
定义 Bean,并用 remoting-destination tag 把它Spring的服务层暴露给Flex
<bean id="employeeServiceDest" class="com.sample.EmployeeService">
<flex:remoting-destination />
</bean>


第五步 删除多余的 Flex 配置文件
只留下service-config.xml文件
将service-config.xml 配置文件从以下格式改为
原有配置
<services>
  <service-include file-path="remoting-config.xml" />
  <service-include file-path="proxy-config.xml" />
  <service-include file-path="messaging-config.xml" />
</services>
改为以下配置
<services>
  <default-channels>
    <channel ref="my-amf"/>
  </default-channels>
</services>

猜你喜欢

转载自wangyuxiang2012.iteye.com/blog/1563361