浏览 5481 次
锁定老帖子 主题:Flex+Spring配置
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-04-08
1、首先是web.xml需要添加flex的配置,增加如下的内容: <listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <!-- MessageBroker Servlet --> <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> <init-param> <param-name>flex.write.path</param-name> <param-value>/WEB-INF/flex</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>FlexMxmlServlet</servlet-name> <display-name>MXML Processor</display-name> <description>Servlet wrapper for the Mxml Compiler</description> <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class> <init-param> <param-name>servlet.class</param-name> <param-value>flex.webtier.server.j2ee.MxmlServlet</param-value> </init-param> <init-param> <param-name>webtier.configuration.file</param-name> <param-value>/WEB-INF/flex/flex-webtier-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>FlexSwfServlet</servlet-name> <display-name>SWF Retriever</display-name> <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class> <init-param> <param-name>servlet.class</param-name> <param-value>flex.webtier.server.j2ee.SwfServlet</param-value> </init-param> <!-- SwfServlet must be initialized after MxmlServlet --> <load-on-startup>2</load-on-startup> </servlet> <servlet> <servlet-name>FlexForbiddenServlet</servlet-name> <display-name>Prevents access to *.as/*.swc files</display-name> <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class> <init-param> <param-name>servlet.class</param-name> <param-value>flex.webtier.server.j2ee.ForbiddenServlet</param-value> </init-param> </servlet> <servlet> <servlet-name>FlexInternalServlet</servlet-name> <servlet-class>flex.bootstrap.BootstrapServlet</servlet-class> <init-param> <param-name>servlet.class</param-name> <param-value>flex.webtier.server.j2ee.filemanager.FileManagerServlet</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> <servlet-mapping> <servlet-name>MessageBrokerServlet</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FlexMxmlServlet</servlet-name> <url-pattern>*.mxml</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FlexSwfServlet</servlet-name> <url-pattern>*.swf</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FlexForbiddenServlet</servlet-name> <url-pattern>*.as</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FlexForbiddenServlet</servlet-name> <url-pattern>*.swc</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>FlexInternalServlet</servlet-name> <url-pattern>/flex-internal/*</url-pattern> </servlet-mapping> 2、在spring的配置文件中增加: <bean id="topoMapViewService" parent="baseTransaction"> <property name="target"> <bean class="com.jeffrey.nms.service.impl.TopoServiceImpl"><!---这里的方法可以通过flex进行调用---> <property name="topoMapDao" ref="topoMapDao" /> <property name="linkInfoDao" ref="linkInfoDao" /> </bean> </property> </bean> 3、然后需要配置flex的配置文件,flex文件下有个services-config.xml, 增加: <factories> <factory id="spring" class="com.jeffrey.nms.web.topo.SpringFactory"/> </factories> 其中类如下(通过网上查的) package com.jeffrey.nms.web.topo; 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; 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 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; } } } } 4、本人做flex时是使用的直接调用java的运程类,以下都是按照这个配置的,还有一个webservice的方法,各位可以收集收集。 在flex文件夹下有个remoting-config.xml文件,需要增加: <destination id="topoMap"> <properties> <factory>spring</factory> <source>topoMapViewService</source> </properties> </destination> 这样topoMap可以在flex进行定义了,如下: <mx:RemoteObject id="topo" destination="topoMap"> 这样flex+spring配置即完成。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-02-16
老大,有没有项目代码给一份出来?需要完整的,谢谢!
|
|
返回顶楼 | |
发表时间:2009-04-14
太感谢您了!在网上看到的例子大多千篇一律都是直接将Spring和Flex集成到一起的,我不太喜欢将Flex等的配置强行加入Spring配置文件,更倾向于楼主这样的完全分离式的配置方式。非常感谢您共享的这段代码,帮我解决了大问题
|
|
返回顶楼 | |