flex java blazeds 注解_Flex+BlazeDS+Spring整合
Flex与服务器通讯有3中方式:HTTPService 组件访问HTTP服务,WebService 组件访问WebService服务,RemoteObject 组件访问Server端对象。第三种方法是最常用最灵活的方法,这种方式通过AMF二进制形式传递数据,需要支持AMF协议的中间件,与java通讯时使用BlazeDS(免费开源)中间件。
新建项目
新建Flex项目,服务器选择J2EE-->BlazeDS,LCDS WAR文件选择blazeds.war文件(下载地址http://download.csdn.net/detail/sjepy/4464788),完成后在FlexDemo.mxml中添加如下代码:
在Servers视图中添加FlexDemo,启动服务,访问http://localhost:8080/FlexDemo/FlexDemo.html,如果出现空列表则表明项目能正常运行。
使用RemoteObject与java通讯
1.在后台新建EmployeeService,返回员工信息到前台flex
packagedemo.flex.service;
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
publicclassEmployeeService {
publicList getEmpList() {
List empList = newArrayList();
Map emp = null;
for(inti =0; i <5; i++) {
emp = newHashMap();
emp.put("name","name"+ i);
emp.put("age",20+ i);
emp.put("email","email"+ i +"@flex.demo");
empList.add(emp);
}
returnempList;
}
}
package demo.flex.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class EmployeeService {
public List getEmpList() {
List empList = new ArrayList();
Map emp = null;
for (int i = 0; i < 5; i++) {
emp = new HashMap();
emp.put("name", "name" + i);
emp.put("age", 20 + i);
emp.put("email", "email" + i + "@flex.demo");
empList.add(emp);
}
return empList;
}
}
2.在WEB-INF/flex/remoting-config.xml文件中添加EmployeeService 对应的 destination
demo.flex.service.EmployeeService
demo.flex.service.EmployeeService
3.修改FlexDemo.mxml,通过RemoteObject直接调用后台EmployeeService的getEmpList()方法
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"creationComplete="init()">
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var empList:ArrayCollection;
protected function empRemote_resultHandler(event:ResultEvent):void
{
empList = event.result as ArrayCollection;
}
protected function empRemote_faultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}
protected function init():void
{
empRemote.getEmpList();
}
]]>
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()">
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
[Bindable]
private var empList:ArrayCollection;
protected function empRemote_resultHandler(event:ResultEvent):void
{
empList = event.result as ArrayCollection;
}
protected function empRemote_faultHandler(event:FaultEvent):void
{
Alert.show(event.toString());
}
protected function init():void
{
empRemote.getEmpList();
}
]]>
4.重新运行项目,界面显示后台返回的员工信息。如果弹出错误信息:HTTP:Status:url:http://localhost:8080/WebContent/messagebroker/amf....打开项目根目录,修改.flexProperties文件中serverContextRoot="/WebContent"为serverContextRoot="/FlexDemo",刷新项目重新运行。(注:我在做本测试时没有问题,但做数据推送测试时后台一直收不到前台订阅信息,浪费了很多时间,一直以为是配置问题,最后才发现是serverContextRoot的原因,建议一定修改serverContextRoot) 整合Spring
springframework及依赖包: aopalliance.jar aspectjweaver.jar cglib-nodep-2.1_3.jar(下载地址http://download.csdn.net/detail/sjepy/5516813) org.springframework.aop-3.0.5.RELEASE.jar org.springframework.asm-3.0.5.RELEASE.jar org.springframework.beans-3.0.5.RELEASE.jar org.springframework.context-3.0.5.RELEASE.jar org.springframework.core-3.0.5.RELEASE.jar org.springframework.expression-3.0.5.RELEASE.jar org.springframework.web.servlet-3.0.5.RELEASE.jar org.springframework.web-3.0.5.RELEASE.jar BlazeDS + Spring整合: org.springframework.flex-1.0.3.RELEASE.jar(下载地址http://download.csdn.net/detail/sjepy/5516755)
2.修改web.xml,去掉所有flex相关配置(如果有的话),添加如下配置:
Spring MVC Dispatcher Servlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
1
Spring MVC Dispatcher Servlet
/messagebroker/*
Spring MVC Dispatcher Servlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
1
Spring MVC Dispatcher Servlet
/messagebroker/*
3.在classpath下添加Spring的配置文件applicationContext.xml:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
4.在EmployeeService上添加注解:
@Component
@RemotingDestination// 把EmployeeService暴露给Flex
@Component
@RemotingDestination// 把EmployeeService暴露给Flex
5.删除WEB-INF/flex下除services-config.xml以外的所有配置文件,修改services-config.xml
前台代码不变,完成后重新运行项目,显示效果和前面一样,至此整合完成。
flex java blazeds 注解_Flex+BlazeDS+Spring整合相关推荐
- flex java 全局拦截_flex + java 过滤敏感词
过滤敏感词这个相对比较容易做到,网上也很多方法,看得比较多的一个方法就是:把所有的敏感词写入到一个properties文件中,程序启动时拼成一个正则表达式.这个也只是比较基础的敏感词过滤器,比较强大的 ...
- flex 连接mysql数据库_Flex+blazeds实现与mySQL数据库的连接
这个小例子通过remoteobject的通讯方法.实现flex与mySQL数据库的交互. BlazeDS 是一个基于服务器的 Java 远程控制 (remoting) 和 Web 消息传递 (mess ...
- Hibernate注解使用以及Spring整合
(1) 简介: 在过去几年里,Hibernate不断发展,几乎成为Java数据库持久性的事实标准.它非常强大.灵活,而且具备了优异的性能.在本文中,我们将了解如何使用Java 5 注释来简化Hiber ...
- 【基于注解方式】Spring整合Kafka
文章目录 1. 添加Maven依赖 2. 配置与参数分离 3. 工具类度内容 4. Producer 消息生产者配置 5. Consumer 消息消费者配置 6. 使用注解监听消息 7. 请求测试 8 ...
- activimq java集成_Java消息队列-Spring整合ActiveMq
1.概述 首先和大家一起回顾一下Java 消息服务,在我之前的博客<Java消息队列-JMS概述>中,我为大家分析了: 消息服务:一个中间件,用于解决两个活多个程序之间的耦合,底层由Jav ...
- java监控activemq,ActiveMQ与Spring整合-监听消息
本课程全程使用目前比较流行的开发工具idea进行开发,涉及到目前互联网项目中常用的高并发解决方案技术, 如 dubbo,redis,solr,freemarker,activeMQ,springBo ...
- flex java 全局拦截_Flex CSS阻止底层内容
想知道是否有人可以帮助我 . 我使用以下代码显示div中的显示内容,但每当我将数据加载到DIV时,它都会正常加载并显示滚动条 . 但是,最后的结果总是显示一半 . 如果我添加如下的间隔,它可以解决问题 ...
- java扫描注解_使用Spring Java注释扫描
我有几个需要用名称注释的类,因此我将注释定义为 @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interf ...
- flex java 开发环境搭建_Flex+JAVA+BlazeDS开发环境配置(Java工程和Flex工程独立)
Flex+JAVA+BlazeDS开发环境配置(Java工程和Flex工程独立) 2019年12月07日 阅读数:7 这篇文章主要向大家介绍Flex+JAVA+BlazeDS开发环境配置(Java工程 ...
最新文章
- php中this,self,parent三个关键字之间的区别(转载)
- 通过Playbook部署LAMP(5)
- HDU - 1251 统计难题(字典树)
- 数学狂想曲(三)——统计杂谈, PID算法, 20世纪10大算法, 矩阵向量的积
- 原来这些元器件最容易引发电路故障。。。
- JVM005_synchronized、同步指令、管程、MESA
- 电池成本涨幅“离谱” 新能源车企涨声一片
- 决策树中的过拟合问题
- 《Effective C#》读书笔记——条目14:尽量减少重复的初始化逻辑.NET资源管理
- 原生js实现点击“上一张”、“下一张”按钮切换图片
- 怎么把mxf转换成mp4?
- 【算法竞赛入门经典(第二版)】_要点提取(第三章)
- 拼图(九宫格,十六宫格)
- 重新思考:在ResNet与Transformer均适用的跳跃连接
- 数值计算中的overflow and underflow
- 计算机密码是空的怎么重置,电脑忘记开机登录密码怎么办? Windows 密码重置 - 合一学院...
- 一个n*n矩阵对角线元素之和
- Matlab代码 多时间尺度优化调度 MATLAB程序含冰蓄冷空调的冷热电联供型微网多时间尺度优化调度
- QT VTK 结合开发
- 使用Office内置的VBA编辑器实现WORD文档的批量查找替换
热门文章
- 常用训练tricks,提升你模型的鲁棒性
- 刷脸支付助力业务增长 网付“唤新计划”全面赋能代理合作伙伴
- 不喜欢现在的工作,如何成功转行?
- 基于SSM框架的家教中介平台系统的设计与实现(源码免费获取)
- 株洲市十三中2021高考成绩查询入口,2021株洲市地区高考成绩排名查询,株洲市高考各高中成绩喜报榜单...
- C++类成员函数转换成函数对象
- 网络营销电商运营新闻博客资讯网站源码 自适应手机端
- 网上炒作的哪些日赚千元不是梦的手机赚钱项目是真的吗
- flutter 底部弹框 选择农历和阳历的日期和时间
- 推荐这三个好用的配音软件给你