flex java spring_Flex+Spring配置

package cn.com.dosoft.tax.factory;

import flex.messaging.services.ServiceException;

import flex.messaging.FactoryInstance;

import flex.messaging.FlexFactory;

import flex.messaging.config.ConfigMap;

import org.springframework.context.ApplicationContext;

import org.springframework.web.context.support.WebApplicationContextUtils;

import org.springframework.beans.BeansException;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;

public class SpringFactory implements FlexFactory {

//定义一个常量资源

private static final String SOURCE = "source";

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.

*/

//创建一个factory实例

public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {

//生成一个Spring的实例

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()

{

//这就是从spring容器中getbean了

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;

}

}

}

}

2、remoting-config配置

springFactory

infoArticleService

3、services-config配置

posted on 2009-03-17 08:03 南山隐士 阅读(992) 评论(0)  编辑  收藏

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值