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

38 篇文章 0 订阅
3 篇文章 0 订阅



 

     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配置文件中配置。

  • 大小: 53.9 KB
  • 大小: 19.4 KB
  • 大小: 10.5 KB
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值