`
牧羊人
  • 浏览: 210917 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

BlaseDS+Spring 整合配置

    博客分类:
  • flex
阅读更多
首先到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  映射的地址。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics