`

Spring BlazeDS Integration 的helloworld程序

    博客分类:
  • Flex
阅读更多

一 前期:
引用

spring-flex-1.0.1.RELEASE
Java 5 or higher
Spring 2.5.6 or higher(需要spring.jar和spring_mvc.jar)
Adobe BlazeDS 3.2 or higher (war包下的WEB-INF文件夹)
把相关jar放入WEB-INF/lib

然后添加BlazeDS到web项目中(可参考前一篇BlazeDS)

二 详细步骤(参考spring-flex-1.0.1.RELEASE 的refrence)
要点:
引用

1.springMVC拦截请求(web.xml文件)
2.配置spring的配置文件(设置拦截处理的beans),映射
3.编写并配置要映射为RemoteObject的bean
4.修改services-config.xml(重要)


1.springMVC拦截请求(web.xml文件)
这里制定了spring的配置文件为
/WEB-INF/config/web-application-config.xml
 <!-- Http Flex Session attribute and binding listener support -->
    <listener>
        <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>

<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/web-application-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all /messagbroker requests to the DispatcherServlet for handling -->
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>    



2.配置spring的配置文件(设置拦截处理的beans),映射
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:flex="http://www.springframework.org/schema/flex"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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 MessageBroker-- 任意选择其中一种-->
<!--方法一 可以指定services- config.xml文件位置 -->
<bean id="_messageBroker" class="org.springframework.flex.core.MessageBrokerFactoryBean" >
	<property name="servicesConfigPath" 
                  value="classpath*:services- config.xml" />
</bean>    	

<!--方法二 这里需要引入一个json的包(具体我忘了),否则报错
<flex:message-broker services-config-path="classpath*:services-config.xml"/>   
-->
<!--方法3 也需要引入json包,否则报错 默认在/WEB-INF/flex/services-config.xml -->
<flex:message-broker/>
 --> 

<!--============  mapping ============-->
<!-- Maps request paths at /* to the BlazeDS MessageBroker -->
<!--这里的_messageBroker为上面那个bean的id-->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /*=_messageBroker
        </value>
    </property>
</bean>

<!-- Dispatches requests mapped to a MessageBroker -->
<bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter"/>    



</beans>




3.编写并配置要映射为RemoteObject的bean
(有3种方法,可参考包自带的参考文献)
<bean id="helloWorldService" class="HelloWorld"></bean>
<flex:remoting-destination ref="helloWorldService" />

这样一个destination id为“helloWorldService”的RemoteObject就好了

4.修改services-config.xml(重要 非官方)
花了我一天时间,参考文献的也不想,后来乱使成功了
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
    <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" 
    	class="flex.messaging.endpoints.AMFEndpoint"/>
    <properties>
        <polling-enabled>false</polling-enabled>
    </properties>
</channel-definition> 	


还要在<services>中加入
<default-channels>
<channel ref="my-amf" />
</default-channels>

然后删掉remoting-config.xml里面上面那段,问我为什么我不知道,反正不怎么做
客户端一调用就fault(对象已拿到)但不存在channel之类的错误


最后客户端
<mx:RemoteObject id="helloRO" destination="helloWorldService" result="resultHandler(event)" fault="faultHandler(event)"/>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics