手把手教你利用flex eclipse整合spring

最先下载FlashBuilder_4_7_LS10_win64.exe试了几个eclipse安装插件都没乐成,包罗myeclipse8.5、spring sts2.9.2、eclipse3.5、j2eeeclipse版本4.2.0,厥后搞了一个FlashBuilder_4_LS10.exe安装完找不到插件安装文件本来这个是单独版,必需插件版才行,最后下载FlashBuilder_4_Plugin_LS10.exe终于设置乐成了,myeclipse8.5不可,spring sts可以了。

spring sts陈设应用跟myeclipse纷歧样,较量雷同eclipse。

用sts整合flex和java有几个步调:

1:新建动态web工程flexweb,建设web.xml

2: blazeds-turnkey-4.0.0.14931.zip解压, 复制blazed两个文件夹flex和lib到WEB-INF下,内里是blaze的jar包和flex设置文件,然后修改web.xml插手blaze支持

<listener> <listener-class>flex.messaging.HttpFlexSession</listener-class> </listener> <!-- MessageBroker Servlet --> <servlet> <servlet-name>MessageBrokerServlet</servlet-name> <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class> <init-param> <param-name>services.configuration.file</param-name> <param-value>/WEB-INF/flex/services-config.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>

3:项目右键,添加/变动项目范例>添加flex范例项目,第一步,应用措施范例选择J2EE,下方选择BlazeDS,第二部根文件夹填入项目在workspase的路径加一个WebContent,如E:\workspaces\sts\flexweb\WebContent,根URL填:8080/flexweb,上下文根目次/flexweb,输出文件夹利用默认E:\workspaces\sts\flexweb\WebContent\flexweb-debug,点击finish
4:转换完成后,目次有些变革,右键项目>properties>flex构建路径,主源文件夹改为flex_src,然后把自动生成的src目次下的flexweb.mxml移动到flex_src下,情况搭建就算完成了

HelloWorld

flexweb.mxml:

<?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.ResultEvent; protected function myFlex_resultHandler(event:ResultEvent):void{ var name:String=event.result as String; Alert.show(name); } protected function button1_clickHandler(event:MouseEvent):void { myFlex.sayHello(txtName.text); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(譬喻处事、值工具)放在此处 --> <s:RemoteObject destination="mytest" result="myFlex_resultHandler(event)"/> </fx:Declarations> <s:Button x="209" y="135" label="按钮"/> <s:TextInput x="166" y="81"/> <s:Label x="10" y="81" text="请输入内容:" fontSize="15" fontWeight="bold" fontFamily="中易黑体"/> </s:Application>

个中

<s:RemoteObject destination="mytest" result="myFlex_resultHandler(event)"/>

指定了一个挪用Java的类Hello,mytest对应到remoting-config.xml

在WEB-INFO/flex目次下remoting-config.xml插手

<destination> <properties> <source>com.hongbo.Hello</source> </properties> </destination>

result对应的是java要领挪用的回调函数
建一个普通java类

package com.hongbo; public class Hello { public String sayHello(String name){ System.out.println("------------------------------------"); return "Hello First Demo " + name; } }

这样就OK了

会见路径是:8080/flexweb/flexweb-debug/flexweb.html


第一次会报404,problems提示无法建设html包装器,右键点击从头建设模板

添加Spring支持

1:web.xml插手

<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

2:src下建设applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <bean> <property> <ref bean="testSpring"/> </property> </bean> <bean/> </beans>

3:WEB-INF/flex/service-config.xml插手

<factories> <factory /> </factories>

添加java类

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdpfy.html