您的位置:首页 > 编程语言 > Java开发

用myEclipse8.5 + flex4 + Spring BlazeDS Integration + Blaze + Gilead整合过程

2011-01-02 10:28 363 查看
以下是框架整合顺序(前提条件是,myEclipse8.5与Flash Bulider4整合在一起);

1、先建立一个普通web工程

2、右键webroot,选择import -> general ->file system,选中BlazeDS文件夹,会自动把BlazeDS的配置文件自动加入web工程

3、添加flex项目类型,修改flex的src路径和flex服务器路径

4、配置流行的S2SH框架(在web.xml配置struts2的action时候要这样<url-pattern>*.action</url-pattern>,否则日后flex不能与java、通信)
5、配置 Spring BlazeDS Integration 和 Gilead


特别说明一下在使用gilead框架时候用到以下2个类的作用;
这2个类是必须的,不用改是官方的!!
类名:SpringApplicationContext
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SpringApplicationContext {
	
	private static SpringApplicationContext instance = null;

	private SpringApplicationContext() {
		super();
	}
	
	public static SpringApplicationContext getInstance() {
		if (instance == null) {
			return new SpringApplicationContext();
		} else {
			return instance;
		}
	}
	
	public Object getSessionFactory() {
		ApplicationContext appContext = WebApplicationContextUtils
				.getWebApplicationContext(flex.messaging.FlexContext
						.getServletConfig().getServletContext());
		return appContext.getBean("sessionFactory");
	}
	
}

作用:这个类是用于适配的,取得sessionFactory





类名:SpringFactory
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

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

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

作用:用来返回实际的Spring管理的bean

在flex中的类与java端的类进行绑定的方法;
package vo{
	import mx.collections.ArrayCollection;
	
	import net.sf.gilead.pojo.actionscript.LightEntity;
	
	/**再现Java端的User类,
	 * 否则Hibernate无法存储信息
	 * *.as类必须和 *.java类 完全一样,字段个数,字段类型
	 * 否则出错
	 */
	[Bindable]
	[RemoteClass(alias="com.oa.beans.User")]
	public class UserVO extends LightEntity{
		/**id*/
		public var id:int;
		/**用户名*/
		public var username:String;
		/**密码*/
		public var password:String;

建一个和Java类完全一样的 as类,as类要继承LightEntity
然后加上
[RemoteClass(alias="com.oa.beans.User")]
也就是为该类对应一个Java为别名
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: