package dsp.factory;
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;
/**
* This interface is implemented by factory components which provide
* instances to the flex messaging framework. To configure flex data services
* to use this factory, add the following lines to your services-config.xml
* file (located in the WEB-INF/flex directory of your web application).
*
* <factories>
* <factory id="spring" class="flex.samples.factories.SpringFactory" />
* </factories>
*
* You also must configure the web application to use spring and must copy the spring.jar
* file into your WEB-INF/lib directory. To configure your app server to use spring,
* you add the following lines to your WEB-INF/web.xml file:
*
* <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>
*
* Then you put your spring bean configuration in WEB-INF/applicationContext.xml (as per the
* line above). For example:
*
* <?xml version="1.0" encoding="UTF-8"?>
* <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
*
* <beans>
* <bean name="weatherBean" class="dev.weather.WeatherService" singleton="true"/>
* </beans>
*
* Now you are ready to define a destination in flex that maps to this existing service.
* To do this you'd add this to your WEB-INF/flex/remoting-config.xml:
*
* <destination id="WeatherService">
* <properties>
* <factory>spring</factory>
* <source>weatherBean</source>
* </properties>
* </destination>
*
* @author Jeff Vroom
*/
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()
/**
* 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();
}
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的集成中,我们需要一个桥梁来连接Flex客户端和Spring服务端。这通常通过创建一个自定义的`FlexFactory`实现,例如`SpringFactory`,它继承自`flex.messaging.FlexFactory`。`SpringFactory`的职责是...
为了使Flex能够访问到Spring容器中的Bean,需要自定义一个`SpringFactory`类,该类继承自`FlexFactory`。在该类中实现`createFactoryInstance`方法来创建具体的Bean实例。 ```java package com.flex.factories; ...
当我们需要在Flex前端和Spring后端之间建立通信时,就需要进行Flex与Spring的整合。这种整合使得Flex客户端能够调用Spring服务端的业务逻辑,实现数据的交互和处理。 **1. SpringFactory方式** SpringFactory方式...
【Flex整合Spring与Hibernate】是将富客户端技术Flex与企业级框架Spring和持久层框架Hibernate进行集成,以实现更高效、灵活的Web应用程序开发。在这样的集成中,Flex作为前端展示层,Spring作为业务逻辑层,而...
### 整合flex-spring-mybatis #### 一、项目背景及目标 本文档旨在详细介绍如何将Flex技术与Spring框架及MyBatis框架进行有效整合,以实现一个高性能且易于维护的企业级应用。通过整合这三种技术,可以充分利用Flex...
5. **集成Spring**:将Spring引入Flex项目,注册Spring配置,处理可能出现的依赖问题,如缺少Spring库,需要从官网下载并添加相应版本的Spring库。 6. **集成Hibernate**:引入Hibernate,配置SessionFactory,并...
首先,集成Spring框架。Spring的核心在于依赖注入(Dependency Injection,DI)和面向切面编程(Aspect-Oriented Programming,AOP),它通过配置文件来管理应用程序的各个组件。在Flex应用中,我们需要将Spring的...
标题中的“Flex3 + Spring配置”指的是在Adobe Flex 3这个富互联网应用程序(RIA)开发框架中集成Spring框架进行后端服务支持的技术实践。Flex3是Adobe Flex的第三个主要版本,它提供了一套用于创建交互式、数据驱动...
### Maven构建全栈式Flex、BlazeDS和Spring集成解决方案——第三部分:整合全部应用 #### 知识点概述 本篇文章将详细介绍如何利用Maven工具链构建一个完整的Flex、BlazeDS和Spring集成解决方案。文章分为三个部分...
标题 "flex3.0+spring2.5+hibernate3.2" 指的是一种集成技术,它将Adobe Flex 3.0(一种用于构建富互联网应用程序的框架)与Spring 2.5(一个Java企业级应用的IOC和AOP容器)和Hibernate 3.2(一个流行的关系型...
### Flex4.5 + Java + Spring + BlazeDS 通信整合详解 #### 一、概述 在现代企业级应用开发中,前后端分离架构已经成为主流趋势之一。本文将详细介绍如何使用Flex 4.5、Java、Spring框架以及BlazeDS进行前后端之间...
为了使Flex能够调用Spring中的bean,我们需要创建一个自定义的`SpringFactory`,它是Flex消息传递框架的一部分。`SpringFactory`实现了`FlexFactory`接口,负责实例化和查找Spring中的bean。下面是一个简化的`...
<factory id="spring" class="flex.samples.factories.SpringFactory"/> ``` 并且在`remoting-config.xml`中配置destination,指定对应的Spring bean: ```xml <factory>spring <source>mortgageBean ``...
- MyEclipse 6.6作为Java开发工具,集成了对Flex的支持。 - Flex Builder 3.0.2专用于Flex应用程序的开发。 - Microsoft SQL Server 2005作为数据库管理系统,存储业务数据。 - Tomcat 6.0.18作为Java Web应用服务器...
搭建Flex的J2EE环境是将Flex应用与Java企业级平台集成的过程,使得Flex客户端能够与后端的Java服务进行通信。以下是如何进行这个过程的详细步骤: 1. **准备软件**: 首先,你需要下载并安装以下软件: - **...
- **连接 RemoteObject**:在 Flex 代码中,可能需要更新 `RemoteObject` 的配置,使其能够通过 Spring 获取 Bean,这通常涉及到在 `remoting-config.xml` 中定义的 `source` 属性的修改。 以上步骤完成后,Flex ...
本项目名为“flex4.5+SSH项目搭建”,其核心是将Adobe Flex与SSH(Struts2、Spring、Hibernate)框架集成,利用Tomcat作为应用服务器。接下来,我们将详细讨论这个项目中涉及的关键知识点。 1. **Flex 4.5**: Adobe...