最佳实践:Flex Spring JAVA BLAZEDS整合
更新时间:2023-08-30 06:53:01 阅读量: 教育文库 文档下载
- 最佳实践案例模版推荐度:
- 相关推荐
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
软件体系最佳实践文档
最佳实践:Flex Spring JAVA BLAZEDS 整合分类:JAVA 与 FLEX 作者:凡彬勇 日期:2011-10-18 QQ: 17486811 导读:使用 Spring 整合 JAVA 与 FLEX 整合
1. 为什么使用 Flex 和 SpringFlex 技术本身和 Java 就有很强的关联性,它提供了一个基于 Eclipse 的 IDE 和 BlazeDS.BlazeDS 是个基于服务端的 Java 远程调用和 Web 消息的一个开源的 技术。有许多应用都是以 Java 为后端处理的。Flex 用于前端。由于 Java 和 Flex 一起频繁的使用。人们很容易就想到 Flex 和 Spring 的整合。有许多企业和组织 已经着手开始使用 Flex 作为用户接口了。在 2008 年末,Spring 社区已经着手 Spring BlazeDS 整合的项目。为 Java 和 Spring 添加更好的 Flex 支持。 默认的情况下 BlazeDS 创建了一个服务端 Java 对象的实例,用它们来完成远程 对象的请求。但是这种方法并不适用于 Spring,因为整个框架使用的服务的对象 都是用 Spring 容器所创建的。 Spring 和 BlazeDS 的整合, Flex 就可以使用 Spring 中的对象了。 其次一般的 JAVA 与 FLEX 通过 BlazeDS 的整合都是要为每一个 remote object 在 remote-config.xml 中 配 置 destination 。 我 们 可 以 通 过 新建 一 个 SpringRemotingDestinationBootstrapService 将 spring bean 导出为 BlazeDS 的 RemotingDestination 以供 flex 调用。
2. 整合步骤1)扩展 AbstractBootstrapServiceBlazeDS 本 身 提 供 一 个 AbstractBootstrapService 的 类 , 该 类 主 要 是 在第 1 页 共 9 页
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
BlazeDS初始化时用于动态创建 services, destinations, and adapters。
SpringRemotingDestinationBootstrapService扩展AbstractBootstrapService。SpringRemotingDestinationBootstrapService 自动导出包含"@Service标注及以FlexService结 尾"的Spring Bean为RemoteObject。
@SuppressWarnings("all")
public class SpringRemotingDestinationBootstrapService extends AbstractBootstrapService {
public static final String DEFAULT_INCLUDE_END_WITH_BEANS = "FlexService";
private static Logger logger =
LoggerFactory.getLogger(SpringRemotingDestinationBootstrapService.class);
private String destChannel;
private String destSecurityConstraint;
private String destScope;
private String destAdapter;
private String destFactory;
private String serviceId;
private String includeEndsWithBeans;
@Override
/**
* 初始化入口
*/
public void initialize(String id, ConfigMap properties) {
serviceId = properties.getPropertyAsString("service-id", "remoting-service");
destFactory = properties.getPropertyAsString("dest-factory", "spring");
destAdapter = properties.getProperty("dest-adapter");
destScope = properties.getProperty("dest-scope");
destSecurityConstraint =
properties.getProperty("dest-security-constraint");
destChannel = properties.getPropertyAsString("dest-channel", "my-amf");
includeEndsWithBeans =
properties.getPropertyAsString("includeEndsWithBeans",
DEFAULT_INCLUDE_END_WITH_BEANS);
Service remotingService = broker.getService(serviceId); if (remotingService == null)
throw createServiceException("not found Service with serviceId:" + serviceId);
createSpringDestinations(remotingService);
}
private ServiceException createServiceException(String message) {
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
ServiceException ex = new ServiceException();
ex.setMessage(message);
return ex;
}
/**
* 将Spring的Service Name自动定义为destination
*/
private void createSpringDestinations(Service remotingService) { WebApplicationContext wac = WebApplicationContextUtils
.getWebApplicationContext(broker.getServletContext()); List<String> addedBeanNames = new ArrayList();
for (String beanName : wac.getBeanDefinitionNames()) {
Class type = wac.getType(beanName);
logger.debug("{}: {}", new Object[]{beanName,
type.getName()});
boolean isCreateSpringDestination = !type
.isAnnotationPresent(com.grgbanking.platform.core.flex.NoneRemotingObject.class)
|| beanName.endsWith(includeEndsWithBeans) || isCreateDestination(beanName, type);
if (isCreateSpringDestination) {
createSpringDestination(remotingService, beanName); addedBeanNames.add(beanName);
}
}
http://www.77cn.com.cn("[Auto Export Spring to
RemotingDestination],beanNames={}", addedBeanNames);
}
protected boolean isCreateDestination(String beanName, Class type) {
return false;
}
/*
* <!-- 动态生成的配置内容 --> <destination id="sampleVerbose"> <channels> <channel
* ref="my-secure-amf" /> </channels> <adapter ref="java-object" /> * <security> <security-constraint ref="sample-users" /> </security> * <properties> <source>http://www.77cn.com.cnpany.SampleService</source>
* <scope>session</scope> <factory>myJavaFactory</factory>
</properties>
* </destination>
*/
protected void createSpringDestination(Service service, String destinationId) {
flex.messaging.services.remoting.RemotingDestination
destination = (flex.messaging.services.remoting.RemotingDestination) service
.createDestination(destinationId);
destination.setSource(destinationId);
destination.setFactory(destFactory);
if (destAdapter != null) {
destination.createAdapter(destAdapter);
}
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
} if (destScope != null) { destination.setScope(destScope); } if (destSecurityConstraint != null) { destination.setSecurityConstraint(destSecurityConstraint); } if (destChannel != null) { destination.addChannel(destChannel); } service.addDestination(destination);
2) 修改SpringFactory并扩展FlexFactory
根据destination的id,将Flex的destination映射为Spring的Bean
public class SpringFactory implements FlexFactory {
private static final String SOURCE = "source";
/**
* This method can be used to initialize the factory itself. It is called
* with configuration parameters from the factory tag which defines the id
* of the factory.
*/
public void initialize(String id, ConfigMap configMap) {
}
/**
* This method is called when we initialize the definition of an instance
* which will be looked up by this factory. It should validate that the
* properties supplied are valid to define an instance. Any valid properties
* used for this configuration must be accessed to avoid warnings about * unused configuration elements. If your factory is only used for * application scoped components, this method can simply return a factory
* instance which delegates the creation of the component to the * FactoryInstance's lookup method.
*/
public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);
instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
return instance;
} // end method createFactoryInstance()
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
/**
* Returns the instance specified by the source and properties arguments.
* For the factory, this may mean constructing a new instance, optionally
* registering it in some other name space such as the session or JNDI, and
* then returning it or it may mean creating a new instance and returning * it. This method is called for each request to operate on the given item
* by the system so it should be relatively efficient.
* <p>
* If your factory does not support the scope property, it report an error
* if scope is supplied in the properties for this instance. */
public Object lookup(FactoryInstance inst) {
SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;
return factoryInstance.lookup();
}
/**
* Spring工厂实例,执行实际的查找动作.
*
* @author yrliang
*
*/
static class SpringFactoryInstance extends FactoryInstance { SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties) {
super(factory, id, properties);
}
@Override
public String toString() {
return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();
}
@Override
public Object lookup() {
Logger logger =
LoggerFactory.getLogger(SpringFactory.class);
ApplicationContext appContext = WebApplicationContextUtils
.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
String beanName = getSource();
try {
logger.debug("lookup(): bean id=" + beanName);
//
flex.messaging.FlexContext.getHttpRequest().getSession().getAttribute(arg0);
return appContext.getBean(beanName);
} catch (NoSuchBeanDefinitionException nexc) {
ServiceException e = new ServiceException();
String msg = "Spring service named '" + beanName + "' does not exist.";
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
e.setMessage(msg);
e.setRootCause(nexc);
e.setDetails(msg);
e.setCode("Server.Processing");
logger.error("",nexc);
throw e;
} catch (BeansException bexc) {
ServiceException e = new ServiceException();
String msg = "Unable to create Spring service named '" + beanName + "' ";
e.setMessage(msg);
e.setRootCause(bexc);
e.setDetails(msg);
e.setCode("Server.Processing");
logger.error("",bexc);
throw e;
}
}
}
}
3) 配置service-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<services-config>
<factories>
<factory id="spring"
class="com.grgbanking.platform.core.flex.spring.SpringFactory"/> </factories>
<services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" /> <service id="spring-remoting-service"
class="com.grgbanking.platform.core.flex.spring.SpringRemotingDestinationBootstrapService">
<!-- 其它生成的RemotingDestination默认属性
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true" />
</adapters>
<default-channels>
<channel ref="my-amf" />
</default-channels>
-->
<properties>
<!--
<service-id></service-id>
<dest-factory></dest-factory>
<dest-adapter></dest-adapter>
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
<dest-scope></dest-scope>
<dest-channel></dest-channel>
<dest-security-constraint></dest-security-constraint>
<includeEndsWithBeans></includeEndsWithBeans> -->
</properties>
</service>
</services>
4) FLEX客户端调用
this.blogFlexService = new RemoteObject("blogFlexService");
//这里需要指定endpoint,因为是动态的RemotingDestination,而静态的
RemotingDestination ,flex编译器会将endpoint编译进源代码.
//这个也是flex编译器需要指定配置文件而导致使用flex经常会犯的错误之一.
this.blogFlexService.endpoint = '../messagebroker/amf';
3. 公司应用案例
这种整合最早是在2010年的FEEL View 5.0中使用,后台的统一平台,FEEL View5.1中都采用这种方法进行整合。FEEL View5.1典型的例子如下:
1) 使用@service标注为RemoteObject,如下:
/**Description: 终端设备信息列表,主要用于银行管机员,终端维护员
* Create Time:2011-8-30
*
*/
@Service
@Transactional
public class TermEquipmentService extends BaseService{
@Autowired
TermEquipmentDao termEquipmentDao;
@Autowired
SysDatadirService sysDatadirService;
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
这样SpringRemotingDestinationBootstrapService在容器启动时会自动将TermEquipmentService注册为RemoteObject.且destination名为:termEquipmentService
2) FLEX使用remote object
<?xml version="1.0" encoding="utf-8"?>
<fx:Object xmlns:fx="http://www.77cn.com.cn/mxml/2009"
xmlns="http://www.77cn.com.cn/parsley"
xmlns:pm="feelview.term.pm.*"
xmlns:message="feelview.term.message.*"
xmlns:delegate="feelview.term.delegate.*"
xmlns:service="feelview.term.service.*"
xmlns:services="platform.services.*"
>
<fx:Declarations>
<!--Description:终端设备信息列表,主要用于银行管机员,终端维护员 Create Time:2011-8-30
Author:Ming.Zhang
Email : zyming1@http://www.77cn.com.cn -->
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<!-- datadir module -->
<pm:TermEquipmentFormPM/>
<message:TermEquipmentMsg/>
<delegate:TermEquipmentDelegate/>
<pm:TermEquipmentModulePM/>
<!-- remote object -->
<services:GRGRemoteObject id="termEquipmentService"
destination="termEquipmentService"/>
</fx:Declarations>
</fx:Object>
3)
/**Description: 终端设备信息列表,主要用于银行管机员,终端维护员
* Create Time:2011-8-30
* Author:Ming.Zhang
* Email : zyming1@http://www.77cn.com.cn
*/
public class TermEquipmentDelegate extends DelegateBase
{
/**远程服务**/
还可以通过注入方式获取
Flex技术本身和Java就有很强的关联性,它提供了一个基于Eclipse的IDE和BlazeDS.BlazeDS是个基于服务端的Java远程调用和Web消息的一个开源的技术。有许多应用都是以Java为后端处理的。Flex用于前端。由于Java和Flex一起频繁的使用。人们很容易就想到Flex和Spring的整合。有许多企业和组织已经着手开始使用Flex作为用户接口了。在2008年末,Spring社区已经着手Spring BlazeDS整合的项目。为Java和Spring添加更好的Flex支持。
软件体系最佳实践文档
[Inject(id="termEquipmentService")] public var ro:RemoteObject;
4. 关于 FlexAdobe Flex 是一套创建富客户端应用(RIAs)的框架.Flex 生成的 swf 文件可以直 接运行在 Flash Player 之中。相比较基于时间轴的 Flash 开发,Flex 框架更适合 那些用传统方式开发应用程序的开发人员。Flex 应用可以使用 Flex builder 来开 发。这套 IDE 是基于 Eclipse 平台开发的。Action Script3 语言是用来访问数据和 创建用户接口组件的。Flex 框架也用到了一种 XML 语言叫做 MXML,它是用来 简化 Flex 开发和布局的。
5. 关于 SpringSpring 是目前最受欢迎的创建企业级应用的 Java 框架。不像传统的 J2EE 开发, Spring 提供了轻量级的容器。使用 Spring 会使应用的测试和开发更为简单。虽 然 Spring 依赖注入的功能最出名,但是它也提供了其他服务端企业程序所需要 的功能。如安全和事务处理。
第 9 页
共 9 页
正在阅读:
最佳实践:Flex Spring JAVA BLAZEDS整合08-30
高等教育数学微积分发展史论文08-15
教学质量监测评价方案04-06
实验七 排序03-12
最适合在家做的几项运动12-10
盐城市水利基本建设工程建设管理工作流程10-16
《化工原理》习题集05-02
七年级历史上册教案11-09
2022年河南财经政法大学财政税务学院财政学考研复试核心题库04-20
收藏家联谊会支部党建工作述职报告02-25
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 整合
- 实践
- BLAZEDS
- 最佳
- Spring
- Flex
- JAVA
- 诺基亚的市场营销环境分析
- 大学生就业问题论文
- 陶慧导游考试培训
- 湖北省黄冈中学2005年春季高二化学期末考试试题
- 参七虫草胶囊对肺纤维化大鼠TGF-β1mRNA表达的影响
- 列二元一次方程组解应用题的基本步骤与设题技巧
- 11月份恒大城营销总结
- 吊车租赁协议
- 2009年四川省凉山州中考数学试题(word版含答案)
- 2002年日语能力测试4级试题及答案
- 高中英语教师工作总结
- 用U盘制作的winPE系统来安装系统(图文教程)
- 银行行业票据解决方案
- 监控设备采购招标文件范本
- 社会主义建设道路的初期探索1
- 水泥稳定碎石基层常见问题及整改、 预防措施
- 指数函数、对数函数、换底公式
- 【试题版】2016年普通高等学校招生全国统一考试文科数学(新课标I卷)
- 小学数学有效课堂教学方法
- 《精选计划》2019年学期年级班主任工作计划范文(四篇)