一直看好spring opensource,如何更好地将blazeds与spring完美结合起来是其目标之一。spring的两大特点分别是依赖注入和切面编程,使用spring框架对于代码污染非常少,鬼知道当初rod johnson怎么搞出来这么一套厉害的东西!拉扯远了,进入正题。

1.什么是spring blazeds integration?

懒得翻译了,自己看吧。

Spring has always aimed to be agnostic to the client technologies being used to access its core services, intentionally leaving options open and letting the community drive the demand for any new first-class integration solutions to be added to the Spring project portfolio. Spring BlazeDS Integration is an answer to the commmunity demand for a top-level solution for building Spring-powered Rich Internet Applications using Adobe Flex for the client-side technology.

BlazeDS is an open source project from Adobe that provides the remoting and messaging foundation for connecting a Flex-based front-end to Java back-end services. Though it has previously been possible to use BlazeDS to connect to Spring-managed services, it has not been in a way that feels "natural" to a Spring developer, requiring the extra burden of having to maintain a separate BlazeDS xml configuration. Spring BlazeDS Integration turns the tables by making the BlazeDS MessageBroker a Spring-managed object, opening up the pathways to a more extensive integration that follows "the Spring way".

2.系统需求。

Java 5 以上

Spring 2.5.6 以上

Adobe BlazeDS 3.2 以上

3.服务端开发。

在服务器端的开发主要涉及了web.xml和applicationContext的配置。

其中web.xml配置如下:定义了spring的分发servlet和其映射的表达式。

<?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> <!-- MessageBroker Servlet --> <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/applicationContext*.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> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>springblazeds.html</welcome-file> </welcome-file-list> <login-config> <auth-method>BASIC</auth-method> </login-config> <!-- 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>

在spring的配置的文件当中,我们需要在头部加上flex的命名空间等:

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"

接着我们必须定义一个MessageBroker的工厂类和指出service-config.xml的路径。

<bean id="_messageBroker" class="org.springframework.flex.core.MessageBrokerFactoryBean"> <property name="servicesConfigPath" value="/WEB-INF/flex/services-config.xml" /> </bean>

如何定义一个映射请求的urlhandler类:

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value>/*=_messageBroker</value> </property> </bean>

再定义一个分发请求的类:

<bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter" />

最后,将我们的服务给暴露出来:

<bean id="productService" class="ProductService"> </bean> <bean id="product" class="org.springframework.flex.remoting.RemotingDestinationExporter"> <property name="messageBroker" ref="_messageBroker"></property> <property name="service" ref="productService"></property> <property name="channels" value="my-amf"></property> </bean>

至此服务端开发完毕。

4.客户端开发。

客户端的开发就显得比较简单了:

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <!--[CDATA[ import mx.messaging.ChannelSet; import mx.messaging.channels.AMFChannel; import mx.messaging.Channel; import mx.controls.Alert; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.rpc.remoting.RemoteObject; private var productService:RemoteObject; private var _productModel:ProductModel; private var productChannel:Channel; private function init():void{ _productModel=new ProductModel(); productService=new RemoteObject(); if(!productChannel){ productChannel=new AMFChannel("my-amf","http://localhost:8080/springblazeds/messagebroker/amf"); var channelSet:ChannelSet=new ChannelSet(); channelSet.addChannel(productChannel); productService.channelSet=channelSet; productService.destination="product"; } } private function getProduct(e:MouseEvent):void{ productService.getProduct(); productService.addEventListener(FaultEvent.FAULT,getProductFaultHandler); productService.addEventListener(ResultEvent.RESULT,getProductResultHandler); } private function getProductFaultHandler(e:FaultEvent):void{ Alert.show(e.fault.toString()); } private function getProductResultHandler(e:ResultEvent):void{ _productModel=e.result as ProductModel; Alert.show(_productModel.productId+" "+_productModel.productName+" "+_productModel.productDetail); } ]]--> </mx:Script> <mx:Form verticalCenter="0" horizontalCenter="0" width="400" height="400"> <mx:Button label="Button" click="getProduct(event)"/> </mx:Form> </mx:Application>

这样配置好客户端和服务端便可以调用开发了,是不是很简单呢?有需要的朋友不妨向我索要代码。

blazeds与spring的结合使用相关推荐

  1. Flex BlazeDS整合Spring在Tomcat下的安全验证

    Flex BlazeDS整合Spring在Tomcat下的安全验证 今天看了BlazeDS Developer Guide,在Tomcat在利用BASIC方法做了个安全验证的实例.Flex Blaze ...

  2. Pomer Flex J2EE (Flex+BlazeDS+Hibernate + spring )框架

    1.为什么使用POMER Pomer是一 个开源的企业信息管理系统基础框架,它提供了一系列企业信息管理系统的基础功能,包括企业组织架构管理,角色权限管理,菜单管理,数据权限控制等功能. Pomer提供 ...

  3. flex blazeds java spring_flex+blazeds+java+spring后台消息推送,有界面维护

    之前写过一篇文章:flex+blazeds+java后台消息推送(简单示例)  ,现在要写的是这个的升级版,改动还是挺多的,在上面的基础上增加了spring配置,还有界面的维护.后台基本上全变了.呵呵 ...

  4. 案例学习BlazeDS+Spring之一(

    BlazeDS4的一个亮点就是与Spring的集成,这大大简化了与FLASH与JEE的集成开发.通过理解BlazeDS4附带的那些精湛的小DEMO,可以很快速的掌握这门技术.虽然案例学习这种方式不太利 ...

  5. 基于Spring Boot+Cloud构建微云架构

    链接:my.oschina.net/u/3636867/blog/1802517 前言 首先,最想说的是,当你要学习一套最新的技术时,官网的英文文档是学习的最佳渠道.因为网上流传的多数资料是官网翻译而 ...

  6. 基于Spring Boot和Spring Cloud实现微服务架构学习--转

    原文地址:http://blog.csdn.net/enweitech/article/details/52582918 看了几周spring相关框架的书籍和官方demo,是时候开始总结下这中间的学习 ...

  7. 基于 Spring Boot 和 Spring Cloud 实现微服务架构

    前言 首先,最想说的是,当你要学习一套最新的技术时,官网的英文文档是学习的最佳渠道.因为网上流传的多数资料是官网翻译而来,很多描述的重点也都偏向于作者自身碰到的问题,这样就很容易让你理解和操作出现偏差 ...

  8. 基于Spring Boot和Spring Cloud实现微服务架构学习

    目录 Spring 顶级框架 Spring cloud子项目 WHAT - 什么是微服务 微服务简介 微服务的具体特征 SOA vs Microservice HOW - 怎么具体实践微服务 客户端如 ...

  9. java后台 flex前台例子_flex+blazeds+java后台消息推送(简单示例)

    现在有个问题需要大家思考一下,有个已经上线了的项目,有好好几千甚至上万的客户在使用了.现在项目开发商想发布一个通知.在今天下午6点需要重新启动服务器,想让在线的人在在预定的时间内都收到消息,让大家做好 ...

最新文章

  1. linux安装python3命令-linux系统下安装python3及其配置
  2. 转载:JQuery制作的选项卡改进版
  3. 通过缓存数据库结果提高PHP性能(转)
  4. vxworks gcc linux,针对VxWorks的GCC交叉编译器无法编译C++
  5. springboot配置热部署
  6. 【计算机基础】 操作系统总结(未完)
  7. B4.Java web部分
  8. 解决办法:无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用)
  9. Java基础(五):多线程
  10. 第二章 Maven的安装和配置
  11. 论文阅读:More Data, More Relations, More Context and More Openness:A Review and Outlook for RE关系抽取的回顾与展望
  12. 量化交易入门,看这篇就够了
  13. HTML 图书销售排行榜
  14. 网络计算机无法访问 没有权限,教您无法访问您可能没有权限使用网络资源怎么解决...
  15. 死磕 Framework准没错,大把的高薪岗位等着你~
  16. 权变理论计算机管理理论,现代管理理论的主要学派
  17. c语言计算利息答案是0.0,ACCP北大青鸟4.0 程序逻辑和C语言实现课本后的习题和上机题目,怎么做?...
  18. GitHub 标星超 26600,TiDB 社区运营的道与术!
  19. 使用鲁大师检测硬盘健康状态
  20. java项目经理负责做什么的,项目经理JAVA岗位职责

热门文章

  1. Unity触发检测和碰撞检测
  2. Nginx 同时运行多个服务
  3. 信修修:固态硬盘各式样,对比起来哪家强?
  4. Python 爬虫 | 获取历史涨停数据
  5. ARFoundation之路-环境配置(iOS)之二
  6. iphone 热点 android,苹果的个人热点功能android手机能用吗
  7. 二叉树Ⅰ · 树型结构 · 二叉树 · 满二叉树 · 完全二叉树 · 二叉树的性质 · 二叉树的存储
  8. Linux虚拟机的远程三种链接,以及各自的上网方式
  9. 【分享】成功将Thinkpad E40 0578M59更换无线网卡AR9280
  10. 一维信号卷积与图像卷积的区别