BlaseDS+Spring 整合配置

  首先到spring网站下载两个工具包(http://www.springsource.org/download)

  1.Spring Framework 2.5.x:spring框架的工具包,版本要在2.5以上。

  2.spring-flex-1.0.1.RELEASE:Spring对BlaseDS支持的工具包。

  3.jackson-core.jar:在测试的过程中依赖此包,Spring工具包中并为提供此包,确实令人郁闷。

                                  这里是我在maven项目找到的jar提供给大家。免得浪费大家的是时间了。

 

  到Adob官方网站下载BlaseDS工具包blazeds-turnkey-3.x.x(http://opensource.adobe.com/wiki/display/blazeds/download+blazeds+3)

 

   接着就是就是建立web服务端工程了进行相关的配置了。 

   web.xml文件配置:注册Spring 的MVC servlet

<!-- 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:flex="http://www.springframework.org/schema/flex"
xsi:schemaLocation="http://www.springframework.org/schema/beans
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  映射的地址。

 参考文档:

   spring-flex-reference.pdf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值