首先到spring网站下载两个工具包(http://www.springsource.org/download)
1.Spring Framework 3.0:spring框架的工具包,版本要在2.5以上。
2.spring-flex-1.0.1.RELEASE:Spring对BlaseDS支持的工具包。
3.jackson-core.jar:在测试的过程中依赖此包,Spring工具包中并为提供此包,确实令人郁闷。
到Adob官方网站下载BlaseDS工具包blazeds-turnkey-3.x.x(http://opensource.adobe.com/wiki/display/blazeds/download+blazeds+3)
接着就是就是建立web服务端工程了进行相关的配置了。
web.xml文件配置:注册Spring 的MVC servle
<!-- blazeDS-spring配置 -->
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
这里org.springframework.web.servlet.DispatcherServlet 要用到spring-webmvc.jar的工具包,可以在Spring Framework 的dist\modules下找到。
applicationContext.xml配置:指定BlazeDS通道配置文件。
<flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml"/>
services-config-path 默认为"/WEB-INF/flex/services-config.xml".services-config.xml配置使用BlazeDS默认就可以。
如果<flex:message-broker> 标签报错,是因为此标签为 spring-flex-1.0.1.RELEASE 提供的,需要对xml头信息作加入以下信息。
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flex="http://www.springframework.org/schema/flex"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/flex
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
最后为flex客户端配置具体的服务。这里同样是在Spring的applicationContext.xml文件<beans>标签中利用<flex:>中配置。参考如下:
<bean id="testService" class=" com.novel.web.service.impl.TestServiceImpl"/>
<flex:remoting-destination ref="testService" channels="my-amf"/>
首先配置个服务的类,再将<flex:remoting-destination> 标签与其相关联,此处访问的服务名默认为"testService"。
注:关于BlazeDS 原先提供的 remoting-config.xml 等文件,不需要在配置了。
到此服务端配置完。flex客户端就可以调用了。客户端代码如下
1.使用remote控件的写法。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
function getData():void{
srv.getData();
}
function handlResult(e:ResultEvent):void
{
trace(e.result);
}
]]>
</mx:Script>
<mx:RemoteObject id="srv" destination="testService" endpoint="messagebroker/amf" result="handlResult(event)" />
<mx:Button click="getData()" x="278.5" y="186" label="点击" width="53"/>
</mx:Application>
注:endpoint属性地址要对应web.xml中的MessageBrokerServlet 映射的地址。
分享到:
相关推荐
整合Flex、Java、hibernate、Spring BlaseDS 形成一个的一个完善的OA系统,能直接运行,运行环境:MyEclipse 、Tomcat 、Sqlserver。
一个用Flex调用JAVA方法的例子ffffffff
四种方式实现Flex页面跳转 在学习Flex的过程中,你可能会遇到Flex页面跳转的问题,本文和大家分享一下,页面在flex里面其实就是一个个的Canvas,vbox,hbox等等之类的东西,看到的不同页面的切换,就是这些元素一...
一个通俗易懂的开发文档,我看完后也能大概了解到blaseds的工作原理,推荐给大家
blaseDS框架实现Flex与J2EE的通信Demo ----------------------------------- 学习笔记-------flex后台通信-------- -----------------------------------
很适合想学cairngorm 的初学者,直接导入eclipse 中就可以运行了,eclipse+tomcat6.0+flex builder 3