package com.hongbo; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; 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 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:修改remoting-config.xml
<destination> <properties> <factory>spring</factory> <source>hello</source> </properties> </destination>
5:修改相应的Java类
package com.hongbo; import com.hongbo.test.TestSpring; public class Hello { private TestSpring testSpring; public void setTestSpring(TestSpring testSpring) { this.testSpring = testSpring; } public String sayHello(String name){ return testSpring.testSpring(name); } }
package com.hongbo.test; public interface TestSpring { String testSpring(String name); }
package com.hongbo.test.impl; import com.hongbo.test.TestSpring; public class TestSpringImpl implements TestSpring{ public String testSpring(String name){ System.out.println("test spring-------------------------------------"+name); return "test spring "+name; } }
最后,flex打印语句trace不会打印到节制台,要先卸载flashplayer再安装一个debuger版的flashplayer,下载flashplayer_uninstall.zip,卸载,下载flashplayer10r12_36_winax_debug.exe,安装,卸载安装后仿佛谷歌欣赏器没影响,然后eclipse修改默认欣赏器为IE,window>preferences>General>Web browser,选择Internet Explorer,最后尚有,启动tomcat后,必需在mxml上面右键debug运行,打开的IE才会打印trace,直接会见网址是不可的。
如有漏掉请指出
您大概感乐趣的文章: