当前位置: 首页 > 工具软件 > Gilead > 使用案例 >

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

祁鸿哲
2023-12-01

以下是框架整合顺序(前提条件是,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 

view plaincopy to clipboardprint?
01.import org.springframework.context.ApplicationContext;  
02.import org.springframework.web.context.support.WebApplicationContextUtils;  
03. 
04.public class SpringApplicationContext {  
05.      
06.    private static SpringApplicationContext instance = null;  
07. 
08.    private SpringApplicationContext() {  
09.        super();  
10.    }  
11.      
12.    public static SpringApplicationContext getInstance() {  
13.        if (instance == null) {  
14.            return new SpringApplicationContext();  
15.        } else {  
16.            return instance;  
17.        }  
18.    }  
19.      
20.    public Object getSessionFactory() {  
21.        ApplicationContext appContext = WebApplicationContextUtils  
22.                .getWebApplicationContext(flex.messaging.FlexContext  
23.                        .getServletConfig().getServletContext());  
24.        return appContext.getBean("sessionFactory");  
25.    }  
26.      
27.} 
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

view plaincopy to clipboardprint?
01.import org.springframework.beans.BeansException;  
02.import org.springframework.beans.factory.NoSuchBeanDefinitionException;  
03.import org.springframework.context.ApplicationContext;  
04.import org.springframework.web.context.support.WebApplicationContextUtils;  
05. 
06.import flex.messaging.FactoryInstance;  
07.import flex.messaging.FlexFactory;  
08.import flex.messaging.config.ConfigMap;  
09.import flex.messaging.services.ServiceException;  
10. 
11.public class SpringFactory implements FlexFactory {  
12.    private static final String SOURCE = "source";  
13. 
14.    public void initialize(String id, ConfigMap configMap) {  
15.    }  
16. 
17.    public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {  
18.        SpringFactoryInstance instance = new SpringFactoryInstance(this, id,  
19.                properties);  
20.        instance.setSource(properties.getPropertyAsString(SOURCE, instance  
21.                .getId()));  
22.        return instance;  
23.    }  
24. 
25.    public Object lookup(FactoryInstance inst) {  
26.        SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;  
27.        return factoryInstance.lookup();  
28.    }  
29. 
30.    static class SpringFactoryInstance extends FactoryInstance {  
31.        SpringFactoryInstance(SpringFactory factory, String id,  
32.                ConfigMap properties) {  
33.            super(factory, id, properties);  
34.        }  
35. 
36.        public String toString() {  
37.            return "SpringFactory instance for id=" + getId() + " source=" 
38.                    + getSource() + " scope=" + getScope();  
39.        }  
40. 
41.        public Object lookup() {  
42.            ApplicationContext appContext = WebApplicationContextUtils  
43.                    .getWebApplicationContext(flex.messaging.FlexContext  
44.                            .getServletConfig().getServletContext());  
45.            String beanName = getSource();  
46.            try {  
47.                return appContext.getBean(beanName);  
48.            } catch (NoSuchBeanDefinitionException nexc) {  
49.                ServiceException e = new ServiceException();  
50.                String msg = "Spring service named '" + beanName  
51.                        + "' does not exist.";  
52.                e.setMessage(msg);  
53.                e.setRootCause(nexc);  
54.                e.setDetails(msg);  
55.                e.setCode("Server.Processing");  
56.                throw e;  
57.            } catch (BeansException bexc) {  
58.                ServiceException e = new ServiceException();  
59.                String msg = "Unable to create Spring service named '" 
60.                        + beanName + "' ";  
61.                e.setMessage(msg);  
62.                e.setRootCause(bexc);  
63.                e.setDetails(msg);  
64.                e.setCode("Server.Processing");  
65.                throw e;  
66.            }  
67.        }  
68.    }  
69.} 
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端的类进行绑定的方法;

view plaincopy to clipboardprint?
01.package vo{  
02.    import mx.collections.ArrayCollection;  
03.      
04.    import net.sf.gilead.pojo.actionscript.LightEntity;  
05.      
06.    /**再现Java端的User类, 
07.     * 否则Hibernate无法存储信息 
08.     * *.as类必须和 *.java类 完全一样,字段个数,字段类型 
09.     * 否则出错 
10.     */ 
11.    [Bindable]  
12.    [RemoteClass(alias="com.oa.beans.User")]  
13.    public class UserVO extends LightEntity{  
14.        /**id*/ 
15.        public var id:int;  
16.        /**用户名*/ 
17.        public var username:String;  
18.        /**密码*/ 
19.        public var password:String; 
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为别名

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/foart/archive/2011/01/02/6112088.aspx

 类似资料: