ITeye博客

FLEX和spring、hibernate的集成

caowei3047 · 2008-12-10 10:03 · Flash-Flex · Spring · Flex · XML · Hibernate · Web · Markdown

FLEX和spring、hibernate的集成

Posted under Web相关 by admin

flex的后台使用spring+hibernate,spring+hibernate的集成方法和j2ee的项目中方法相同。主要是flex和spring的集成

编写SpringFactory.java类:

java 代码

 

  1. package com.fire.spring;
  2. import org.springframework.context.ApplicationContext;
  3. import org.springframework.web.context.support.WebApplicationContextUtils;
  4. import org.springframework.beans.BeansException;
  5. import org.springframework.beans.factory.NoSuchBeanDefinitionException;
  6. import flex.messaging.FactoryInstance;
  7. import flex.messaging.FlexFactory;
  8. import flex.messaging.config.ConfigMap;
  9. import flex.messaging.services.ServiceException;
  10. public class SpringFactory implements FlexFactory
  11. {
  12. private static final String SOURCE = “source”;
  13. public void initialize(String id, ConfigMap configMap) {}
  14. public FactoryInstance createFactoryInstance(String id, ConfigMap properties)
  15. {
  16. SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);
  17. instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
  18. return instance;
  19. } // end method createFactoryInstance()
  20. public Object lookup(FactoryInstance inst)
  21. {
  22. SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;
  23. return factoryInstance.lookup();
  24. }
  25. static class SpringFactoryInstance extends FactoryInstance
  26. {
  27. SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties)
  28. {
  29. super(factory, id, properties);
  30. }
  31. public String toString()
  32. {
  33. return “SpringFactory instance for id=” + getId() + “ source=” + getSource() + “ scope=” + getScope();
  34. }
  35. public Object lookup()
  36. {
  37. ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());
  38. String beanName = getSource();
  39. try
  40. {
  41. return appContext.getBean(beanName);
  42. }
  43. catch (NoSuchBeanDefinitionException nexc)
  44. {
  45. ServiceException e = new ServiceException();
  46. String msg = “Spring service named ’” + beanName + “‘ does not exist.”;
  47. e.setMessage(msg);
  48. e.setRootCause(nexc);
  49. e.setDetails(msg);
  50. e.setCode(“Server.Processing”);
  51. throw e;
  52. }
  53. catch (BeansException bexc)
  54. {
  55. ServiceException e = new ServiceException();
  56. String msg = “Unable to create Spring service named ’” + beanName + “‘ ”;
  57. e.setMessage(msg);
  58. e.setRootCause(bexc);
  59. e.setDetails(msg);
  60. e.setCode(“Server.Processing”);
  61. throw e;
  62. }
  63. }
  64. }
  65. }

配置WEB-INF/flex/service-config.xml,在最后添加如下代码:

xml 代码

xml 代码

 

  1. <factories>
  2. <factory id=“spring” class=“com.fire.spring.SpringFactory”/>
  3. factories>

 在使用remoteobject的时候,配置remote-config.xml时,如下进行配置:

xml 代码

 

  1. <destination id=“provinceService”>
  2. <properties>
  3. <factory>spring</factory>
  4. <source>provinceService</source>
  5. </properties>
  6. </destination>

 

« FLEX带进度指示的文件上传

FMS回调FLEX端的Function »

评论(1)

  1. #1 楼 · happyday · 2009-03-17 16:47

    不知道博主能不能看懂这个例子,反正我是看不懂 最好加工一下变成你自己的东西,

评论功能维护中,当前仅展示历史评论。