flex+blazeds+spring

前提:

下载blazed,把war包下面的web-inf下面的lib中的所有jar包加载到项目中去,并且把里面的flex文件夹放到web-info下面(当然这个路径是可以配置的)。因为用到springMVC所以需要导入 spring-MVC的jar包

1.web.xml中添加Spring MVC转发

  

 <!-- MessageBroker Servlet 单独为Flex配置xml-->  
    <servlet>  
        <servlet-name>flex</servlet-name>  
        <servlet-class>  
            org.springframework.web.servlet.DispatcherServlet  
        </servlet-class>  
        <init-param>  
           <param-name>contextConfigLocation</param-name>  
            <param-value>  
                classpath:flex-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>flex</servlet-name>  
        <url-pattern>/messagebroker/*</url-pattern>  
    </servlet-mapping>

 

 2.配置flex-application-config.xml 

  

<?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.0.xsd">

   <bean id="_messageBroker"
		class="org.springframework.flex.core.MessageBrokerFactoryBean">
		<property name="servicesConfigPath">
			<value>/WEB-INF/flex/services-config.xml</value>
		</property>
	</bean>
	<!-- Maps request paths at /* to the BlazeDS MessageBroker -->
	<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" />
	<!-- 配置flex与service的交换类 -->
	<bean id="product"
		class="org.springframework.flex.remoting.RemotingDestinationExporter">
		<property name="messageBroker" ref="_messageBroker" />
		<property name="service" ref="dlyhService" />			
		<property name="destinationId" value="dlyhService" />				
		<property name="includeMethods" value="checkUser" />
		<!--
		<property name="excludeMethods" value="create, delete" />		 
		<property name="channels" value="my-amf, my-secure-amf" />
		 -->		
	  </bean>
	  <bean id="test"
	   class="com.td.framework.Test">
	    <property name="names">
	      <value>zhangsan</value>
	    </property>
	   </bean>				
</beans>		

    对于上面用到的dlyhService,我是在applicationContext.xml总定义,在此我就不贴出来了。下面的test可有可无。我是之前做测试用的

 

3.flex页面

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<fx:Script>
			<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			private function onResultHandler(event:ResultEvent):void{			
			Alert.show(String(event.result));
			}
			private function onFaultHandler(event:FaultEvent):void{
			Alert.show(String(event.fault), "Fault!");
			}
			private function btn_Click1EventHandler(event:MouseEvent):void{
			dbRemote.getNames();
			}
			private function btn_Click2EventHandler(event:MouseEvent):void{
			dbRemote.getParams();
			}
			

				protected function button1_clickHandler(event:MouseEvent):void
				{
					// TODO Auto-generated method stub
					dbRemote.checkUser(yhm.text,mm.text);
				}

			]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->

		<mx:RemoteObject id="dbRemote" destination="dlyhService" endpoint="http://localhost:8080/TSProject/messagebroker/amf" result="onResultHandler(event)" fault="onFaultHandler(event)">
		</mx:RemoteObject>		
	</fx:Declarations>		
	<s:Panel x="150" y="55" width="250" height="200" title="登陆">
		<s:Label x="21" y="29" text="用户名"/>
		<s:Label x="21" y="59" text="密码"/>
		<s:TextInput x="94" y="19" id="yhm"/>
		<s:TextInput x="94" y="59" id="mm"/>
		<s:Button x="61" y="105" label="提交" click="button1_clickHandler(event)"/>
	</s:Panel>
	
</s:Application>

 

对于上面的flex下面的配置文件并没有做任何修改。

此文为原文,如果不明白的可以留言,互相交流提高。

 

给大家介绍一篇很好的文章

http://www.infoq.com/cn/articles/spring-blazeds-integration

 

 

你可能感兴趣的:(spring,xml,bean,servlet,Flex)