`
laowood
  • 浏览: 120966 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Flex+BlazeDS+Spring的一个项目笔记(2)

阅读更多

applicationContext.xml 配置如下

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
	<bean id="loginBean" class="com.lms.shop.login.LoginDAO">
		<property name="dataSource" ref="websphereDataSource"></property>
	</bean> 
	<!--data source 是从 websphere配置的 jndi 获取-->
	<bean id="websphereDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="webspherejndi"/>
        		<property name="resourceRef" value="false"/>
	</bean>
	<!--事务管理-->
	<bean id="trans" class="org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean"/>
	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
		<property name="transactionManager" ref="trans"/>
	</bean>
</beans>

  

 

 

flex 有四个配置文件不可缺少 在 flex文件夹下可以看到

三种通信方式的配置(messaging-config.xml,proxy-config.xml,remoting-config.xml)和总控配置(services-config.xml).

此工程中只用到了 remoting通信方式,简单灵活。

为了让spring 来管理 flex 和 服务器端通信 services-config.xml 稍微修改一下。

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
    <services>
        <service-include file-path="remoting-config.xml" />
    </services>
	<!--这里配置一个 factorices -->
	<factories>
		<factory id="spring" class="com.lms.shop.factories.SpringFactory"/>
	</factories>
    <security>
        <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
    </security>
    <channels>
        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>
        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>
    </channels>

    <logging>
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>false</includeLevel>
                <includeCategory>false</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
    </logging>

    <system>
        <redeploy>
            <enabled>false</enabled>
        </redeploy>
    </system>

</services-config>

 

 

 SpringFactory.java 的内容如下    ,,客户端调用的 FlexServlet 全由这个工厂来生成

package com.lms.shop.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;

/**
 * This interface is implemented by factory components which provide
 * instances to the flex messaging framework.  To configure flex data services
 * to use this factory, add the following lines to your services-config.xml
 * file (located in the WEB-INF/flex directory of your web application).
 *
 *	&lt;factories&gt;
 *     &lt;factory id="spring" class="flex.samples.factories.SpringFactory" /&gt;
 *  &lt;/factories&gt;
 *
 * You also must configure the web application to use spring and must copy the spring.jar
 * file into your WEB-INF/lib directory.  To configure your app server to use spring,
 * you add the following lines to your WEB-INF/web.xml file:
 *
 *   &lt;context-param&gt;
 *        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
 *        &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
 *   &lt;/context-param&gt;
 *
 *   &lt;listener&gt;
 *       &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
 *   &lt;/listener&gt;
 * 
 * Then you put your spring bean configuration in WEB-INF/applicationContext.xml (as per the
 * line above).  For example:
 * 
 *  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
 *  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
 *   
 *  &lt;beans&gt;
 *    &lt;bean name="weatherBean" class="dev.weather.WeatherService" singleton="true"/&gt;
 *  &lt;/beans&gt;
 *  
 * Now you are ready to define a destination in flex that maps to this existing service. 
 * To do this you'd add this to your WEB-INF/flex/remoting-config.xml:
 *
 *  &lt;destination id="WeatherService"&gt;
 *      &lt;properties&gt;
 *          &lt;factory&gt;spring&lt;/factory&gt;
 *          &lt;source&gt;weatherBean&lt;/source&gt;
 *      &lt;/properties&gt;
 *  &lt;/destination&gt;
 *
 * @author Jeff Vroom
 */
public class SpringFactory implements FlexFactory
{
    private static final String SOURCE = "source";

    /**
     * This method can be used to initialize the factory itself.  It is called with configuration
     * parameters from the factory tag which defines the id of the factory.  
     */
    public void initialize(String id, ConfigMap configMap) {}

    /**
     * This method is called when we initialize the definition of an instance 
     * which will be looked up by this factory.  It should validate that
     * the properties supplied are valid to define an instance.
     * Any valid properties used for this configuration must be accessed to 
     * avoid warnings about unused configuration elements.  If your factory 
     * is only used for application scoped components, this method can simply
     * return a factory instance which delegates the creation of the component
     * to the FactoryInstance's lookup method.
     */
    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()

    /**
     * Returns the instance specified by the source
     * and properties arguments.  For the factory, this may mean
     * constructing a new instance, optionally registering it in some other
     * name space such as the session or JNDI, and then returning it
     * or it may mean creating a new instance and returning it.
     * This method is called for each request to operate on the
     * given item by the system so it should be relatively efficient.
     * <p>
     * If your factory does not support the scope property, it
     * report an error if scope is supplied in the properties
     * for this 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;
            } 
        }
        
    } 

} 

 

5
1
分享到:
评论
1 楼 NewTamato 2009-08-24  
你的这个写的全都是代码,不知道对于flex和spring整合的具体的道理,可否告知?

相关推荐

    Flex4+Blazeds4.0+Spring3.0+hibernate2.5.2整合笔记

    本篇笔记主要介绍了如何将 Flex4、Blazeds4.0、Spring3.0 和 hibernate2.5.2 进行整合,实现一个完整的富互联网应用程序。下面是对笔记中关键部分的详细解释: 准备工作 在开始整合之前,需要准备以下软件和资源:...

    Flex+spring+hibernate整合视频学习交流part_2

    2. **Flex与Spring的通信**:介绍 BlazeDS 或 GraniteDS 等中间件,它们作为Flex和Spring应用之间的桥梁,处理AMF(Action Message Format)消息的传输,使得Flex客户端可以调用后端的Spring服务。 3. **Flex的数据...

    Blaze+Spring整合资料

    4. "Flex 开发学习笔记2 - 采用的架构 BlazeDS + Spring + Hibernate" 可能是一个开发者的学习笔记,详细记录了构建基于这三个技术的完整应用过程,包括配置、数据绑定和事务管理。 5. "快速搭建Spring BlazeDS ...

    flex学习笔记

    【Flex学习笔记】这篇笔记主要涉及的技术栈是Flex框架,结合BlazeDS、Spring和Hibernate进行Web应用开发。Flex是一种用于构建富互联网应用程序(RIA)的客户端技术,它基于ActionScript和MXML,通常用于创建交互式的...

    flex3读书笔记----flex整合hibernate

    2. **BlazeDS**: BlazeDS 是 Adobe 提供的一个开源项目,它允许 Flex 客户端与Java服务器进行实时的双向通信。在本例中,BlazeDS 作为 Flex 和 Hibernate 集成的中间件,实现了 AMF (Action Message Format) 数据...

    BlazeDS 开发资料

    BlazeDS是Adobe公司推出的一款开源的服务器端技术,它主要负责在Flex应用程序与Java后端之间提供数据推送服务,实现了富互联网应用(RIA)与服务器之间的实时通信。本资料包包含了两份重要的资源,分别是《BlazeDS...

    Flex For JSP.jar

    新建 文本文档.txt 可能是与这个项目相关的文档,但没有更具体的信息,我们只能猜测它可能是安装指南、API参考、示例代码或者开发过程中的笔记。 使用Flex for JSP,开发者可以: 1. 创建动态、交互性强的用户界面...

    笔记4马鉴.docx

    2. **PureMVC**:PureMVC不仅仅是一个Flex框架,它也适用于多种面向对象的开发环境,如Java和PHP。其优点是提供了丰富的示例和最佳实践,但学习曲线陡峭,需要开发者具备深厚的团队协作和架构经验。PureMVC的理论化...

    Flex与Java交互通讯视频详解

    Flex与Java交互通讯是Web开发中的一个重要话题,它涉及到客户端与服务器端的高效协同工作。Flex,作为Adobe的开源框架,主要用于构建富互联网应用程序(RIA),而Java则是一种广泛使用的后端开发语言,能提供强大的...

Global site tag (gtag.js) - Google Analytics