手把手教你使用flex eclipse整合spring
最先下載FlashBuilder_4_7_LS10_win64.exe試了幾個(gè)eclipse安裝插件都沒(méi)成功,包括myeclipse8.5、spring sts2.9.2、eclipse3.5、j2eeeclipse版本4.2.0,后來(lái)搞了一個(gè)FlashBuilder_4_LS10.exe安裝完找不到插件安裝文件原來(lái)這個(gè)是單獨(dú)版,必須插件版才行,最后下載FlashBuilder_4_Plugin_LS10.exe終于配置成功了,myeclipse8.5不行,spring sts可以了。
spring sts部署應(yīng)用跟myeclipse不一樣,比較類(lèi)似eclipse。
用sts整合flex和java有幾個(gè)步驟:
1:新建動(dòng)態(tài)web工程flexweb,創(chuàng)建web.xml
2: blazeds-turnkey-4.0.0.14931.zip解壓, 復(fù)制blazed兩個(gè)文件夾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:項(xiàng)目右鍵,添加/更改項(xiàng)目類(lèi)型>添加flex類(lèi)型項(xiàng)目,第一步,應(yīng)用程序類(lèi)型選擇J2EE,下方選擇BlazeDS,第二部根文件夾填入項(xiàng)目在workspase的路徑加一個(gè)WebContent,如E:\workspaces\sts\flexweb\WebContent,根URL填http://localhost:8080/flexweb,上下文根目錄/flexweb,輸出文件夾使用默認(rèn)E:\workspaces\sts\flexweb\WebContent\flexweb-debug,點(diǎn)擊finish
4:轉(zhuǎn)換完成后,目錄有些變化,右鍵項(xiàng)目>properties>flex構(gòu)建路徑,主源文件夾改為flex_src,然后把自動(dòng)生成的src目錄下的flexweb.mxml移動(dòng)到flex_src下,環(huán)境搭建就算完成了
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> <!-- 將非可視元素(例如服務(wù)、值對(duì)象)放在此處 --> <s:RemoteObject id="myFlex" destination="mytest" result="myFlex_resultHandler(event)"/> </fx:Declarations> <s:Button x="209" y="135" label="按鈕" click="button1_clickHandler(event)"/> <s:TextInput x="166" y="81" id="txtName"/> <s:Label x="10" y="81" text="請(qǐng)輸入內(nèi)容:" fontSize="15" fontWeight="bold" fontFamily="中易黑體"/> </s:Application>
其中
<s:RemoteObject id="myFlex" destination="mytest" result="myFlex_resultHandler(event)"/>
指定了一個(gè)調(diào)用Java的類(lèi)Hello,mytest對(duì)應(yīng)到remoting-config.xml
在WEB-INFO/flex目錄下remoting-config.xml加入
<destination id="mytest"> <properties> <source>com.hongbo.Hello</source> </properties> </destination>
result對(duì)應(yīng)的是java方法調(diào)用的回調(diào)函數(shù)
建一個(gè)普通java類(lèi)
package com.hongbo; public class Hello { public String sayHello(String name){ System.out.println("------------------------------------"); return "Hello First Demo " + name; } }
這樣就OK了
訪問(wèn)路徑是http://localhost:8080/flexweb/flexweb-debug/flexweb.html
第一次會(huì)報(bào)404,problems提示無(wú)法創(chuàng)建html包裝器,右鍵點(diǎn)擊重新創(chuàng)建模板
添加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下創(chuàng)建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/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <bean id="hello" class="com.hongbo.Hello"> <property name="testSpring"> <ref bean="testSpring"/> </property> </bean> <bean id="testSpring" class="com.hongbo.test.impl.TestSpringImpl"/> </beans>
3:WEB-INF/flex/service-config.xml加入
<factories> <factory id="spring" class="com.hongbo.SpringFactory" /> </factories>
添加java類(lèi)
package com.hongbo; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import flex.messaging.FactoryInstance; import flex.messaging.FlexFactory; import flex.messaging.config.ConfigMap; import flex.messaging.services.ServiceException; public class SpringFactory implements FlexFactory { private static final String SOURCE = "source"; public void initialize(String id, ConfigMap configMap) { } public FactoryInstance createFactoryInstance(String id, ConfigMap properties) { SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties); instance.setSource(properties.getPropertyAsString(SOURCE, instance .getId())); return instance; } // end method createFactoryInstance() public Object lookup(FactoryInstance inst) { SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst; return factoryInstance.lookup(); } static class SpringFactoryInstance extends FactoryInstance { SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties) { super(factory, id, properties); } public String toString() { return "SpringFactory instance for id=" + getId() + " source=" + getSource() + " scope=" + getScope(); } public Object lookup() { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext()); String beanName = getSource(); try { return appContext.getBean(beanName); } catch (NoSuchBeanDefinitionException nexc) { ServiceException e = new ServiceException(); String msg = "Spring service named '" + beanName + "' does not exist."; e.setMessage(msg); e.setRootCause(nexc); e.setDetails(msg); e.setCode("Server.Processing"); throw e; } catch (BeansException bexc) { ServiceException e = new ServiceException(); String msg = "Unable to create Spring service named '" + beanName + "' "; e.setMessage(msg); e.setRootCause(bexc); e.setDetails(msg); e.setCode("Server.Processing"); throw e; } } } }
4:修改remoting-config.xml
<destination id="mytest"> <properties> <factory>spring</factory> <source>hello</source> </properties> </destination>
5:修改相應(yīng)的Java類(lèi)
package com.hongbo; import com.hongbo.test.TestSpring; public class Hello { private TestSpring testSpring; public void setTestSpring(TestSpring testSpring) { this.testSpring = testSpring; } public String sayHello(String name){ return testSpring.testSpring(name); } }
package com.hongbo.test; public interface TestSpring { String testSpring(String name); }
package com.hongbo.test.impl; import com.hongbo.test.TestSpring; public class TestSpringImpl implements TestSpring{ public String testSpring(String name){ System.out.println("test spring-------------------------------------"+name); return "test spring "+name; } }
最后,flex打印語(yǔ)句trace不會(huì)打印到控制臺(tái),要先卸載flashplayer再安裝一個(gè)debuger版的flashplayer,下載flashplayer_uninstall.zip,卸載,下載flashplayer10r12_36_winax_debug.exe,安裝,卸載安裝后好像谷歌瀏覽器沒(méi)影響,然后eclipse修改默認(rèn)瀏覽器為IE,window>preferences>General>Web browser,選擇Internet Explorer,最后還有,啟動(dòng)tomcat后,必須在mxml上面右鍵debug運(yùn)行,打開(kāi)的IE才會(huì)打印trace,直接訪問(wèn)網(wǎng)址是不行的。
如有遺漏請(qǐng)指出
相關(guān)文章
Flex上傳本地圖片并提前瀏覽的實(shí)現(xiàn)方法
個(gè)性頭像最終需要上傳到服務(wù)器的文件系統(tǒng)中,但是程序希望在用戶選擇后直接有個(gè)預(yù)覽,針對(duì)這個(gè)問(wèn)題,下面有個(gè)不粗的實(shí)現(xiàn),希望對(duì)大家有所幫助2014-01-01flex中使用css樣式修改TextArea滾動(dòng)條的皮膚代碼
使用css樣式修改TextArea滾動(dòng)條的皮膚,具體示例代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08flex導(dǎo)出excel具體實(shí)現(xiàn)
flex導(dǎo)出excel的前提是需要插件as3xls-1.0.1.swc,下面為大家介紹下具體的實(shí)現(xiàn)2014-01-01Flex字體加粗問(wèn)題只能對(duì)英文的字體加粗
在flex中對(duì)label進(jìn)行字體加粗的時(shí)候,只能對(duì)英文的字體加粗,而中文的就不可以加粗,解決方法如下,希望對(duì)大家有所幫助2014-01-01Flex中TitleWindow傳值思路及實(shí)現(xiàn)
這篇文章主要介紹了Flex中TitleWindow傳值思路及實(shí)現(xiàn),需要的朋友可以參考下2014-05-05flex中使用RadioButtonGroup時(shí)取出所選項(xiàng)的值的方法
flex中的RadioButtonGroup想必大家并不陌生吧,在本文將為大家介紹下在使用RadioButtonGroup時(shí)如何取出所選項(xiàng)的值,感興趣的朋友可以參考下2013-12-12flex tree自動(dòng)顯示橫向滾動(dòng)條實(shí)現(xiàn)代碼
flex tree自動(dòng)顯示橫向滾動(dòng)條想必有很多的朋友都不會(huì)吧,下面與大家分享下具體的實(shí)現(xiàn)方法,感興趣的你可不要錯(cuò)過(guò)了哈2013-05-05使用flex中的httpservice方法與java進(jìn)行交互
這篇文章主要介紹了使用flex中的httpservice方法與java進(jìn)行交互,需要的朋友可以參考下2014-02-02