Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1894535
  • 博文数量: 606
  • 博客积分: 9991
  • 博客等级: 中将
  • 技术积分: 5725
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-17 19:07
文章分类

全部博文(606)

文章存档

2011年(10)

2010年(67)

2009年(155)

2008年(386)

分类:

2009-04-20 20:14:11

=============================================

remoting-config.xml:

        

             spring

             springTest

        

    

==============================================================

services-config.xml:

    

      

    

==============================================================

web.xml: 和struts整合spring一样

    

       contextConfigLocation

       /WEB-INF/applicationContext.xml

    

    

       org.springframework.web.context.ContextLoaderListener

    

============================================================

applicationContext.xml




 
    
      Hello
    

 

============================================================

SpringFactory.java文件

package flex.samples.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;

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;

             }

         }

       

     }

}

=============================================

SpringTest.java

package flex.samples;

public class SpringTest {

private String description;


public String getDescription(String name) {
    return description + name;
}


public void setDescription(String description) {
    this.description = description;
}
}

=============================================

Flex.mxml:




   import mx.rpc.events.ResultEvent;
  function gg(evnet:ResultEvent):void{
   var ff:String = evnet.result as String;
   ggg.text = ff;
  }
  function remotingSayHello():void{
   var sname:String = nameInput.text;
   myspring.getDescription();
  }
  ]]>





=============================================

阅读(1587) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~