flex和spring的連接

 Flex的的對象傳輸方式可謂簡單又方便,spring和flex又是如何連接,srping用到的jar包大致如下:org.springframework.beans, org.springframework.context,和org.springframework.web ,flex是blazeds.war。

springFactory.java文件:

 

package com.iteye.factories;

import flex.messaging.FactoryInstance;
import flex.messaging.FlexContext;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

@SuppressWarnings("unused")
public class SpringFactory implements FlexFactory {

	private static final String SOURCE = "source";

	public void initialize(String identifier, ConfigMap configMap) {
	}

	public FactoryInstance createFactoryInstance(String identifier,
			ConfigMap properties) {
		SpringFactoryInstance instance = new SpringFactoryInstance(this,
				identifier, properties);
		instance.setSource(properties.getPropertyAsString("source", instance
				.getId()));
		return instance;
	}

	public Object lookup(FactoryInstance instance) {
		return ((SpringFactoryInstance) instance).lookup();
	}

	static class SpringFactoryInstance extends FactoryInstance {
		private static final String SERVER_PROCESSING = "Server.Processing";

		SpringFactoryInstance(SpringFactory factory, String identifier,
				ConfigMap properties) {
			super(factory, identifier, properties);
		}

		public String toString() {
			return "SpringFactory instance for id=" + getId() + " source="
					+ getSource() + " scope=" + getScope();
		}

		public Object lookup() {
			ServiceException exception;
			String msg;
			ApplicationContext appContext = WebApplicationContextUtils
					.getWebApplicationContext(FlexContext.getServletConfig()
							.getServletContext());

			String beanName = getSource();
			try {
				return appContext.getBean(beanName);
			} catch (NoSuchBeanDefinitionException nexc) {
				exception = new ServiceException();
				msg = "Spring service named '" + beanName + "' does not exist.";
				exception.setMessage(msg);
				exception.setRootCause(nexc);
				exception.setDetails(msg);
				exception.setCode("Server.Processing");
				throw exception;
			} catch (BeansException bexc) {
				exception = new ServiceException();
				msg = "Unable to create Spring service named '" + beanName
						+ "' ";
				exception.setMessage(msg);
				exception.setRootCause(bexc);
				exception.setDetails(msg);
				exception.setCode("Server.Processing");
				throw exception;
			}
		}
	}
}

 

 

web.xml配置:

 

 

   <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/applicationContext.xml</param-value>
    </context-param>

<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


 <listener>                                                        
         <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>


  <servlet>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <display-name>MessageBrokerServlet</display-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>1</load-on-startup>
    </servlet>

 

 

applicationContext.xml測試配置:

 

	<bean id="testDAO" class="com.iteye.testDAO">
		<property name="sessionFactory" ref="mySessionFactory" />
	</bean>

 

 flex下services-config.xml配置:

 

<factories>
        <factory id="spring" class="com.pega.factories.SpringFactory"/>
    </factories>

 

 

對象傳輸方式用到的remoting-config.xml配置:

 

<destination id="test">
        <properties>
            <factory>spring</factory>         
            <source>testDAO</source>
        </properties>
    </destination>

 然後寫好這個test類,在mxml代碼中調用remoteObject組件調用這個類了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值