`

Flex、Spring整合:blazeds

阅读更多
准备:
1、下载blazeds 4.x,下载地址:http://download.macromedia.com/pub/livecycle/blazeds/4_0/blazeds-bin-4.0.0.14931.zip


2、部署blazeds至tomcat,访问http://localhost:8080/blazeds/messagebroker/amf,显示空白页,则部署成功


整合:
====================服务端开发========================================
1、建立一测试Service:
public class GuestListService implements Serializable, IGuestListService {

	private static final long serialVersionUID = 3552207441192189726L;

	public List<Guest> getGuestList() {
		List<Guest> guestList = new ArrayList<Guest>();
		guestList.add(new Guest("Guest One"));
		guestList.add(new Guest("Guest Two"));
		guestList.add(new Guest("Guest Three"));
		guestList.add(new Guest("Guest Four"));
		return guestList;
	}
}


2、配置bean:在blazeds/WEB-INF/下新建applicationContext.xml文件,添加
<beans>
	<bean id="guestListService" class="com.sky.flexonspring.services.GuestListService" />
</beans>


3、修改web.xml文件,添加spring支持
<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>


4、打开blazeds/WEB-INF/flex/services-config.xml,添加
<factories>
		<factory id="spring" class="com.sky.flexonspring.factories.SpringFactory" />
	</factories>

使得flex的bean对象创建交由spring负责
SpringFactory类的代码如下:
package com.sky.flexonspring.factories;

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.
 * 
 * @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;
			}
		}
	}
}


5、将service公开,提供flex客户端调用:打开blazeds/WEB-INF/flex/remoting-config.xml,增加如下配置
<destination id="guestListService">
		<properties>
			<factory>spring</factory>
			<source>guestListService</source>
		</properties>
	</destination>


至此,服务端整合、开发完毕

====================客户端开发========================================
1、新建flex应用程序,添加remoteObject调用:
<mx:RemoteObject id="ro"
					 destination="guestListService"
					 endpoint="http://localhost:8080/blazeds/messagebroker/amf"
					 result="resultHandler(event)"
					 fault="faultHandler(event)"/>

注意这边的guestListService整合就是与remoting-config.xml中配置的destination的id保持一致
ro.getGuestList()
这段代码调用就得到调用
GuestListService.getGuestList()
后的List<Guest> 列表
private function resultHandler(event:ResultEvent):void
			{
				guestListDP = ArrayCollection(event.result);
			}


至此客户端就得到了服务器端的数据了,下面就是根据业务自由处理了。

效果图:


  • 大小: 20.8 KB
分享到:
评论

相关推荐

    Flex、Spring整合:Spring BlazeDS Integration

    标题中的“Flex、Spring整合:Spring BlazeDS Integration”指的是在Java后端使用Spring框架与前端Flex应用程序进行集成的一种技术方案。BlazeDS是Adobe提供的一个开源项目,它为富互联网应用(RIA)提供了数据推送...

    Flex Spring JAVA BLAZEDS整合

    【Flex Spring JAVA BLAZEDS整合】是一种技术实践,它将Adobe Flex的前端展示层与Spring框架的后端业务逻辑层紧密结合,利用BlazeDS作为中间件进行数据传输。Flex作为一个强大的RIA(富互联网应用程序)开发平台,常...

    Flex Spring框架成BlazeDS

    Flex Spring框架与BlazeDS的整合是Web开发中一个重要的技术组合,主要用于构建富互联网应用程序(Rich Internet Applications,RIA)。Flex作为Adobe推出的基于Flash Player或Adobe AIR运行时的客户端开发框架,提供...

    Flex_Spring_BlazeDS完整整合包

    Flex Spring BlazeDS整个web工程,其中FlexServer是整合后的myeclipse web project工程,FlexText是Flex测试工程。在tomcat中运行测试无误。

    flex-spring-blazeds demo

    《Flex-Spring-BlazeDS整合应用探索》 在当今的Web开发领域,富互联网应用程序(Rich Internet Applications,简称RIA)已经成为提升用户体验的重要手段。Flex作为Adobe提供的RIA开发框架,以其强大的图形用户界面...

    Flex-Spring-JAVA-BLAZEDS.rar_Flex spring_flex_flex java

    描述中的“Flex Spring JAVA BLAZEDS整合,永固整合将flex与Spring整合”表明这个压缩包文件包含了如何将这三者结合在一起的教程或指南。这种整合允许开发者利用Flex的富客户端能力,Spring的后端服务管理,以及...

    Spring整合flex-Spring BlazeDS Integration-带项目demo

    Spring整合Flex是一个重要的技术主题,尤其对于构建富互联网应用程序(RIA)时。Spring BlazeDS Integration是Spring框架的一个组件,它提供了与Adobe Flex的无缝集成,允许后端Java服务与前端Flex客户端进行通信。...

    spring blazeds 整合实例(源码)

    标题中的“Spring BlazeDS 整合实例”是指在Java开发环境中,使用Spring框架与BlazeDS进行集成,以便实现富互联网应用(RIA)的后台数据交互。BlazeDS是Adobe提供的一个开源项目,它允许Flex客户端与Java服务器之间...

    flex4+spring+blazeds整合技术

    《Flex4+Spring+BlazeDS整合技术详解》 在当今的Web开发中,富互联网应用程序(Rich Internet Applications,简称RIA)已经成为一种趋势,而Flex作为Adobe提供的RIA开发框架,结合Spring的优秀企业级服务管理和...

    flex+spring +BlazeDs+spring+ibatis+Cairngorm整合教程(以前下的,忘了来源了,感激这位大神...)

    标题中的“flex+spring +BlazeDs+spring+ibatis+Cairngorm整合教程”涉及到的是一个基于Adobe Flex前端、Spring后端服务、BlazeDS作为数据通信中间件、Spring框架进行服务管理以及Ibatis作为持久层操作的典型企业级...

    flex + spring + BlazeDS + google App JDO 实现一个CRUD.

    标题中的“flex + spring + BlazeDS + google App JDO 实现一个CRUD”是指使用Adobe Flex作为前端开发工具,Spring框架作为后端服务层,BlazeDS作为数据推送中间件,以及Google App Engine的JDO(Java Data Objects...

    flex+Spring+Hibernate+Cairngorm+BlazeDS+Spring BlazeDS Integration整合框架

    使用flex 4.5 + Spring 3.0 + Hibernate 3.3 + Cairngorm 2.2.1 + BlazeDS 3.3.0 + Spring BlazeDS Integration 1.0.3整合出的一个登录的小demo·

    Flex 与 Spring整合

    Flex与Spring整合是将Adobe Flex前端技术和Spring后端框架相结合,实现富互联网应用程序(Rich Internet Applications,RIA)的开发。这种结合使得开发者可以利用Flex的交互性和表现力,以及Spring的强大企业服务...

    spring整合flex所需jar包

    - 设置BlazeDS:在服务器端部署BlazeDS,配置对应的Spring上下文配置文件,指定要暴露给Flex的Spring服务。 - 创建Flex客户端:在Flex项目中,使用RemoteObject或HTTPService组件来调用服务器端的Spring服务。配置...

    Spring 整合 Flex 包

    Spring 整合 Flex 是一种将 Adobe Flex 前端技术和 Spring 框架后端服务进行集成的方法,目的是为了创建富互联网应用程序(Rich Internet Applications,RIA)。Spring Flex 提供了全面的支持,使得 Flex 应用程序...

    flex-spring blazeds integration基本框架搭建记录

    《Flex-Spring BlazeDS 整合基础架构构建详解》 在现代Web开发中,富互联网应用程序(Rich Internet Applications,简称RIA)的需求日益增长,而Flex作为Adobe提供的RIA开发框架,因其强大的图形用户界面和与服务器...

    flex+spring flex整合

    将Flex与Spring整合,可以充分利用两者的优点,构建出既美观又稳定的应用程序。 **BlazeDS 和 Spring BlazeDS Integration** 整合Flex和Spring的关键在于让Flex客户端能够方便地访问Spring管理的Bean,而BlazeDS和...

Global site tag (gtag.js) - Google Analytics