当前位置: 代码迷 >> Web前端 >> 替SSH架构的java web项目添加flex支持
  详细解决方案

替SSH架构的java web项目添加flex支持

热度:258   发布时间:2012-10-24 14:15:58.0
为SSH架构的java web项目添加flex支持



?

???? java+flex开发环境在此不再介绍,SSH架构的java项目的搭建也不再多说(示例项目采用tomcat作为服务器,端口为9080)。

??? 首先,解压blazeds.war,将得到的messageing-config.xml,proxy-config.xml,remoting-config.xml,services-config.xml四个文件复制到WEB-INF下的flex文件夹下,将以下jar包复制到项目中,web.xml中添加以下代码

<servlet>
  <display-name>MessageBrokerServlet</display-name>
  <servlet-name>MessageBrokerServlet</servlet-name>
  <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
  <init-param>
   <param-name>services.configuration.file</param-name>
   <param-value>/WEB-INF/flex/services-config.xml</param-value>
  </init-param>
  <load-on-startup>11</load-on-startup>
 </servlet>

?

?

右击项目,选择添加/更变项目类型------添加flex项目类型,如下图:<!--StartFragment -->?

?

?选择j2ee服务器,

,至此,项目添加flex支持完成,在此分享两个工具类,

package com.iman.common;

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.config.ConfigMap;   
import  flex.messaging.services.ServiceException;   
   
public class SpringFactoryInstance  extends  FactoryInstance   
{   
    SpringFactoryInstance(FlexSpringFactory factory, String id, ConfigMap properties)   
    {   
        super (factory, id, properties);   
    }   
    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();   
            throw  e;   
        }   
        catch  (BeansException bexc)   
        {   
            ServiceException e = new  ServiceException();   
            throw  e;   
        }    
    }   
       
}    

?

package com.iman.common;

import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;

public class FlexSpringFactory implements FlexFactory {

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

	public void initialize(String arg0, ConfigMap arg1) {

	}

}

?remoting-config.xml中配置远程对象,需要从springfactory中获取的可以采取以下配置

<destination id="topDisplayDataManager">
		<properties>
			<factory>springFactory</factory>
			<source>topDisplayDataManager</source>
		</properties>
	</destination>

?

当然,这个bean你必须事先在spring配置文件中配置。

  相关解决方案