工程需要整合Spring和Flex,在网上众多方法中找到了下面这种,记录留存。

个人认为该方法更适合在已有Spring框架的工程中添加Flex时使用,对原工程内容(主要指配置文件)改动较小。

1.添加Spring,在web.xml文件里添加配置

<context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>/WEB-INF/applicationContext.xml</param-value>

</context-param>

<listener>

 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

2.在flex的services-config.xml文件里添加Spring工厂

<factories>
<factory id="spring" class="com.flex.factories.SpringFactory"/>
</factories>

3.在Spring里面定义bean

<bean id="testClass" class="com.....TestService">
<property name="dataSource" ref="dataSource"/>
</bean>

4.在flex的远程对象配置文件里配置远程对象,这里要指定远程对象的创建工厂为第2步配置的工厂,远程对象的source要指向Spring里定义的bean

<destination id="test">
<properties>
<factory>spring</factory>
<source>testClass</source>
</properties>
</destination>

5.在页面就可以使用远程对象了

private function send():void{

    test.doSomething(...);

}

附:需要的SpringFactory

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceException; public class SpringFactory implements FlexFactory
{
private static final String SOURCE = "source"; public void initialize(String id, ConfigMap configMap) {} 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() public Object lookup(FactoryInstance inst)
{
SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;
return factoryInstance.lookup();
} static class SpringFactoryInstance extends FactoryInstance
{
SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties)
{
super(factory, id, properties);
} public String toString()
{
return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();
} public Object lookup()
{
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
String beanName = getSource(); try
{
return appContext.getBean(beanName);
}
catch (NoSuchBeanDefinitionException nexc)
{
ServiceException e = new ServiceException();
String msg = "Spring service named '" + beanName + "' does not exist.";
e.setMessage(msg);
e.setRootCause(nexc);
e.setDetails(msg);
e.setCode("Server.Processing");
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");
throw e;
}
} } }

Flex整合Spring的更多相关文章

  1. 【Java EE 学习 81】【CXF框架】【CXF整合Spring】

    一.CXF简介 CXF是Apache公司下的项目,CXF=Celtix+Xfire:它支持soap1.1.soap1.2,而且能够和spring进行快速无缝整合. 另外jax-ws是Sun公司发布的一 ...

  2. Mybatis整合Spring

    根据官方的说法,在ibatis3,也就是Mybatis3问世之前,Spring3的开发工作就已经完成了,所以Spring3中还是没有对Mybatis3的支持.因此由Mybatis社区自己开发了一个My ...

  3. mybatis入门_一对多,多对多映射以及整合spring框架

    一.一对多映射. 1.1 一对多映射之根据多的一方关联查询一的一方 示例:查询出具体的订单信息,同时也查询出来订单的用户信息. 引入的订单表如下所示: 框选出来的为具体的外键. 订单的Pojo类如下所 ...

  4. 《SSM框架搭建》三.整合spring web

    感谢学习http://blog.csdn.net/zhshulin/article/details/37956105#,还是修改了spring到最新的版本和接口开发示例 根据前一篇日志,已经有了myb ...

  5. Maven 整合 spring profile实现多环境自动切换

    Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...

  6. TinyFrame续篇:整合Spring IOC实现依赖注入

    上一篇主要讲解了如何搭建基于CodeFirst的ORM,并且在章节末我们获取了上下文对象的实例:BookContext.这节主要承接上一篇,来讲解如何整合Spring IOC容器实现控制反转,依赖注入 ...

  7. Ehcache 整合Spring 使用页面、对象缓存

    Ehcache 整合Spring 使用页面.对象缓存 Ehcache在很多项目中都出现过,用法也比较简单.一 般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布 ...

  8. webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成

    首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...

  9. (转)Ehcache 整合Spring 使用页面、对象缓存

    Ehcache在很多项目中都出现过,用法也比较简单.一般的加些配置就可以了,而且Ehcache可以对页面.对象.数据进行缓存,同时支持集群/分布式缓存.如果整合Spring.Hibernate也非常的 ...

随机推荐

  1. jQuery :lt()选择器

    定义和用法 :lt() 选择器选取 index 值小于指定数字的元素.(不包含指定值) index 值从 0 开始.(从0开始计数) 最常见的用法:与其他选择器一起使用,选取指定组合中特定序号之前的元 ...

  2. ajax 实现异步请求

    ajax实现异步请求: function onclicks() { $.ajax( { url:'../hhh/columnSearch.do',// 跳转到 action // data: {tab ...

  3. HDU 3030 - Increasing Speed Limits

    Problem Description You were driving along a highway when you got caught by the road police for spee ...

  4. 在Linux上使用cmake创建CodeBlocks工程

    最近在linux上使用cmake,对于使用GUI习惯的还真不能适应,真是想尽一切办法把原来使用cmake的工程创建成CodeBlocks工程.工程小了还能接受,工程大了太麻烦了. 看了一下cmake的 ...

  5. python函数与方法装饰器

    之前用python简单写了一下斐波那契数列的递归实现(如下),发现运行速度很慢. def fib_direct(n): assert n > 0, 'invalid n' if n < 3 ...

  6. mysql 更新 语句中 的 safe_mode

    在mysql5中,可以设置safe mode,比如在一个更新语句中UPDATE table_name SET bDeleted=0;执行时会错误,报:You are using safe update ...

  7. Android 开源控件系列_1

    第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...

  8. 数独破解c++代码

    数独破解c++代码 #include <iostream> #include <cstring> #include <cstdio> #include <st ...

  9. NetworkManager——Linux强大的网络管理工具

    NetworkManager服务:NetworkManager - Linux Networking made Easy NetworkManager简介:NetworkManager由一个管理系统网 ...

  10. WPF(MultiTrigger)

    原文 http://blog.csdn.net/haifengzhilian/article/details/8822098 <Window x:Class="TestResource ...