博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Flex整合Spring
阅读量:4652 次
发布时间:2019-06-09

本文共 3500 字,大约阅读时间需要 11 分钟。

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

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

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

contextConfigLocation
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener

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

3.在Spring里面定义bean

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

spring
testClass

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;              }          }                }    }

 

 

转载于:https://www.cnblogs.com/EagleOfEble/p/3232598.html

你可能感兴趣的文章
父类引用指向子类对象
查看>>
网页如何实现下载功能
查看>>
IT男专用表白程序
查看>>
读《大道至简》第六章感想
查看>>
ef linq 中判断实体中是否包含某集合
查看>>
章三 链表
查看>>
Solution for Concurrent number of AOS' for this application exceeds the licensed number
查看>>
CSE 3100 Systems Programming
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
Java Security(JCE基本概念)
查看>>
Linux Supervisor的安装与使用入门
查看>>
创建 PSO
查看>>
JasperReport报表设计4
查看>>
项目活动定义 概述
查看>>
团队冲刺04
查看>>
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>