Flex+Struts2+Spring整合开发
关于Flex的整合问题,做一个配置简介,另外对容易出错的地方跟大家说说 如果有错误,感谢大家指正。 (开始之前,我必须承认,题目是个噱头,只要有Spring这个超强粘合剂,多个框架可以很容易整合。) 如果是熟悉Spring MVC则完全不需要使用Struts2,这里为了先前项目的表现层可以平滑过度到Flex,才沿用了Struts2 另外,这里主要讲讲Flex怎么与Spring整合,至于Spring与其他框架整合,不在文章内 1.假定你已经配置好web应用并且增加了BlazeDS和导入spring-flex包(使用到的包会在文章最后展示) 配置web.xml [code="xml"] flexweb contextConfigLocation classpath:applicationContext.xml struts2 org.apache.struts2.dispatcher.FilterDispatcher org.springframework.web.context.ContextLoaderListener flex org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/classes/flex-application-config.xml 1 struts2 /* flex /messagebroker/* index.html index.jsp [/code] 以上内容实质上是两个Web Framework,一个是Struts2(标记名为struts2),一个是Spring MVC(标记名为flex) 这里Spring MVC为flex的RemotingObject提供映射和Flex与Server通讯MessageBroker类 配置flex-application-config.xml [code="xml"] [/code] 大家注意到,标签引入http://www.springframework.org/schema/flex/spring-flex-1.0.xsd文件,便可以使用 标记了。 但是这样写虽然简便,但在初学的时候,还是最好理解它的机制吧 以上的内容可以改写成: [code="xml"] /WEB-INF/flex/services-config.xml /*=_messageBroker [/code] 大家注意: “http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">内容被移除” 完全是一个标准的Spring配置文件了。 这里把之前web.xml的/messagebroker/*映射完全对应到/*=_messageBroker,也就是 org.springframework.flex.core.MessageBrokerFactoryBean类中,生成MessageBroker,而MessageBroker是Flex与Server通信的关键 而MessageBrokerHandlerAdapter适配器会取得MessageBroker的实例,使用endpoint = broker.getEndpoint(endpointPath, contextPath);取得端点 endpoint.service(request, response);发送 如果你熟悉Spring MVC,请原谅我又唠叨一遍- -# 现在通讯问题完毕,那么远程调用呢? 我们接着来: 定义一个java类: [code="java"] package example.fx; public class DataBean { private String name = ""; private String params = ""; public String getName() { return this.getClass().getName()+ " : " +name; } public void setName(String name) { this.name = name; } public String getParams() { return params; } public void setParams(String params) { this.params = params; } } [/code] 在flex-application-config.xml中,增加: 当然,你也可以写到Spring的其他配置文件中,例如本文中Spring管理Struts2的那个applicationContext.xml(参照web.xml) [code="xml"] Hello Flex!!! [/code] 这里只生成了一dataBean的实例,但是前段Flex如何访问呢? 在在flex-application-config.xml中继续增加 [code="xml"] [/code] 这里又是图开发速度,然而这部分可以有如下三种写法,分别是: a.[code="xml"] Hello Flex!!! [/code] b.[code="xml"] [/code] c.[code="xml"] [/code] [color=red]当然,dataBean中并没有read, update, create, delete方法,这里只是演示用[/color]. 经过这么多繁琐的过程,终于Flex可以访问到Server的java类了。 我们新建一个MXML Application文件 [code="xml"] [/code] 服务器启动后,运行你的MXML Application,点击Flash上的两个按钮,看看结果吧 如果你跟我一样懒 那么配置一下Struts,在URL敲一下地址,不用每次都运行你的MXML文件,[color=blue]特别是为了安全起见,你把MXML文件编译到web/WEB-INF/下的时候[/color] 以下是struts.xml [code="xml"] /WEB-INF/page/flex/{1}.swf [/code] 有几点说明: 1.flex的四个配置文件完全没有更改,并且使用默认channel. 2.有文章说,在remoting-service配置远程访问 比如: [code="xml"] example.fx.DataBean [/code] 这种方式和在文章中的flex-application-config.xml配置的 [color=blue] [/color]是一致的,也就是说,如果你在remoting-service配置了,就不需要在Spring配置文件中,反之亦然,如果你在remoting-service和flex-application-config.xml都配置了,web服务器启动的时候会抛异常,提示你bean id已经注册. 3.有不少文章中,MXML中RomoteObject是这样配置的 [code="xml"] [/code] 如果使用默认配置,即remoting-service.xml文件中会有一个默认channel配置,这样写是完全没有必要的,你只需要在 [code="xml"] [/code]定义一个server的端点 上面的写法这相当于你另外写了一个AMFChannel,并且使用管道去接(ChannelSet里可以放很多channel) jar包: Spring 使用Spring 3.0.0.M2 Struts 使用Struts 2.0.4 Flex 使用默认BlazeDS包和org.springframework.flex-1.0.0.RC2.jar包 稍后设置一下下载地址 ---------------------------------------------------------------- BlazeDS: [url]http://opensource.adobe.com/wiki/display/blazeds/Release+Builds[/url] org.springframework.flex-1.0.0.RC2.jar:
挺好的,不过对于外行人来说我还是有点迷糊
希望楼主下次给个helloWorld的工程下载
谢谢楼长,能不能给个下载地址!~~~~
下载地址呢????