Flex+Spring配置

Flex+Spring配置

关键字: flex spring

    flex拓扑图制作只是一个简单的例子,可以运行,只是简单的呈现部分,如果要实现具体的拓扑图的功能,需要连接数据库,这里只简单说说flex与spring的结合,有了spring,再与hibernate以及struts就简单多了。
     1、首先是web.xml需要添加flex的配置,增加如下的内容:
     
Java代码
  1.   
  2.         class>flex.messaging.HttpFlexSessionclass>   
  3.         
  4.        
  5.        
  6.        
  7.         MessageBrokerServlet   
  8.         MessageBrokerServlet   
  9.         class>flex.messaging.MessageBrokerServletclass>   
  10.            
  11.             services.configuration.file   
  12.             /WEB-INF/flex/services-config.xml   
  13.           
  14.            
  15.             flex.write.path   
  16.             /WEB-INF/flex   
  17.            
  18.         1   
  19.        
  20.   
  21.        
  22.         FlexMxmlServlet   
  23.         MXML Processor   
  24.         Servlet wrapper for the Mxml Compiler   
  25.         class>flex.bootstrap.BootstrapServletclass>   
  26.            
  27.             servlet.class   
  28.             flex.webtier.server.j2ee.MxmlServlet   
  29.            
  30.            
  31.             webtier.configuration.file   
  32.             /WEB-INF/flex/flex-webtier-config.xml   
  33.            
  34.        1   
  35.        
  36.   
  37.        
  38.         FlexSwfServlet   
  39.         SWF Retriever   
  40.         class>flex.bootstrap.BootstrapServletclass>   
  41.            
  42.             servlet.class   
  43.             flex.webtier.server.j2ee.SwfServlet   
  44.            
  45.            
  46.         2   
  47.        
  48.   
  49.        
  50.         FlexForbiddenServlet   
  51.         Prevents access to *.as/*.swc files   
  52.         class>flex.bootstrap.BootstrapServletclass>   
  53.            
  54.             servlet.class   
  55.             flex.webtier.server.j2ee.ForbiddenServlet   
  56.            
  57.        
  58.   
  59.        
  60.         FlexInternalServlet   
  61.         class>flex.bootstrap.BootstrapServletclass>   
  62.            
  63.             servlet.class   
  64.             flex.webtier.server.j2ee.filemanager.FileManagerServlet   
  65.            
  66.         10   
  67.        
  68.   
  69.        
  70.         MessageBrokerServlet   
  71.         /messagebroker/*   
  72.        
  73.   
  74.        
  75.         FlexMxmlServlet   
  76.         *.mxml   
  77.        
  78.   
  79.        
  80.         FlexSwfServlet   
  81.         *.swf   
  82.        
  83.   
  84.        
  85.         FlexForbiddenServlet   
  86.         *.as   
  87.        
  88.   
  89.        
  90.         FlexForbiddenServlet   
  91.         *.swc   
  92.        
  93.   
  94.        
  95.         FlexInternalServlet   
  96.         /flex-internal/*   
  97.        
  98.       

        flex.messaging.HttpFlexSession
     
    
    
    
        MessageBrokerServlet
        MessageBrokerServlet
        flex.messaging.MessageBrokerServlet
        
            services.configuration.file
            /WEB-INF/flex/services-config.xml
       
        
            flex.write.path
            /WEB-INF/flex
        
        1
    

    
        FlexMxmlServlet
        MXML Processor
        Servlet wrapper for the Mxml Compiler
        flex.bootstrap.BootstrapServlet
        
            servlet.class
            flex.webtier.server.j2ee.MxmlServlet
        
        
            webtier.configuration.file
            /WEB-INF/flex/flex-webtier-config.xml
        
       1
    

    
        FlexSwfServlet
        SWF Retriever
        flex.bootstrap.BootstrapServlet
        
            servlet.class
            flex.webtier.server.j2ee.SwfServlet
        
        
        2
    

    
        FlexForbiddenServlet
        Prevents access to *.as/*.swc files
        flex.bootstrap.BootstrapServlet
        
            servlet.class
            flex.webtier.server.j2ee.ForbiddenServlet
        
    

    
        FlexInternalServlet
        flex.bootstrap.BootstrapServlet
        
            servlet.class
            flex.webtier.server.j2ee.filemanager.FileManagerServlet
        
        10
    

    
        MessageBrokerServlet
        /messagebroker/*
    

    
        FlexMxmlServlet
        *.mxml
    

    
        FlexSwfServlet
        *.swf
    

    
        FlexForbiddenServlet
        *.as
    

    
        FlexForbiddenServlet
        *.swc
    

    
        FlexInternalServlet
        /flex-internal/*
    
    

    2、在spring的配置文件中增加:
   
Java代码
  1. "topoMapViewService" parent="baseTransaction">   
  2.             "target">   
  3.                     
  4.                             class="com.jeffrey.nms.service.impl.TopoServiceImpl">   
  5.                             "topoMapDao" ref="topoMapDao" />   
  6.                             "linkInfoDao" ref="linkInfoDao" />   
  7.                        
  8.                
  9.        
    
                
                        
                                
                                
                        
                
        
    

    3、然后需要配置flex的配置文件,flex文件下有个services-config.xml,
增加:
   
Java代码
  1.   
  2.   "spring" class="com.jeffrey.nms.web.topo.SpringFactory"/>   
  3.   
    
      
    
    

    其中类如下(通过网上查的)
    
Java代码
  1.     package com.jeffrey.nms.web.topo;   
  2.   
  3. import org.springframework.context.ApplicationContext;   
  4. import org.springframework.web.context.support.WebApplicationContextUtils;   
  5. import org.springframework.beans.BeansException;   
  6. import org.springframework.beans.factory.NoSuchBeanDefinitionException;   
  7.   
  8. import flex.messaging.FactoryInstance;   
  9. import flex.messaging.FlexFactory;   
  10. import flex.messaging.config.ConfigMap;   
  11. import flex.messaging.services.ServiceException;   
  12.   
  13. public class SpringFactory implements FlexFactory   
  14. {   
  15.     private static final String SOURCE = "source";   
  16.   
  17.        
  18.     public void initialize(String id, ConfigMap configMap) {}   
  19.   
  20.       
  21.     public FactoryInstance createFactoryInstance(String id, ConfigMap properties)   
  22.     {   
  23.         SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);   
  24.         instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));   
  25.         return instance;   
  26.     } // end method createFactoryInstance()   
  27.   
  28.      
  29.     public Object lookup(FactoryInstance inst)   
  30.     {   
  31.         SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;   
  32.         return factoryInstance.lookup();   
  33.     }    
  34.   
  35.   
  36.     static class SpringFactoryInstance extends FactoryInstance   
  37.     {   
  38.         SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties)   
  39.         {   
  40.             super(factory, id, properties);   
  41.         }   
  42.   
  43.   
  44.         public String toString()   
  45.         {   
  46.             return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope();   
  47.         }   
  48.   
  49.         public Object lookup()    
  50.         {   
  51.             ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());   
  52.             String beanName = getSource();   
  53.   
  54.             try  
  55.             {   
  56.                 return appContext.getBean(beanName);   
  57.             }   
  58.             catch (NoSuchBeanDefinitionException nexc)   
  59.             {   
  60.                 ServiceException e = new ServiceException();   
  61.                 String msg = "Spring service named '" + beanName + "' does not exist.";   
  62.                 e.setMessage(msg);   
  63.                 e.setRootCause(nexc);   
  64.                 e.setDetails(msg);   
  65.                 e.setCode("Server.Processing");   
  66.                 throw e;   
  67.             }   
  68.             catch (BeansException bexc)   
  69.             {   
  70.                 ServiceException e = new ServiceException();   
  71.                 String msg = "Unable to create Spring service named '" + beanName + "' ";   
  72.                 e.setMessage(msg);   
  73.                 e.setRootCause(bexc);   
  74.                 e.setDetails(msg);   
  75.                 e.setCode("Server.Processing");   
  76.                 throw e;   
  77.             }    
  78.         }   
  79.            
  80.     }    
  81.   
  82. }    
  83.       
    package com.jeffrey.nms.web.topo;

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;
    } // end method createFactoryInstance()

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

} 
    

    4、本人做flex时是使用的直接调用java的运程类,以下都是按照这个配置的,还有一个webservice的方法,各位可以收集收集。
     在flex文件夹下有个remoting-config.xml文件,需要增加:
    
Java代码
  1.  "topoMap">   
  2.   
  3.     spring   
  4.     topoMapViewService   
  5.   
  6. lt;/destination>   
     
    
        spring
        topoMapViewService
    
   
    

     这样topoMap可以在flex进行定义了,如下:
  
   这样flex+spring配置即完成。

你可能感兴趣的:(Flex,spring,flex,servlet,properties,string,class)