最先下载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填http://localhost: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 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="请输入内容:" fontsize="15" fontweight="bold" fontfamily="中易黑体"/>
</s:application>
其中
<s:remoteobject id="myflex" destination="mytest" result="myflex_resulthandler(event)"/>
指定了一个调用java的类hello,mytest对应到remoting-config.xml
在web-info/flex目录下remoting-config.xml加入
<destination id="mytest">
<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了
访问路径是http://localhost: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/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类
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:修改相应的java类
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打印语句trace不会打印到控制台,要先卸载flashplayer再安装一个debuger版的flashplayer,下载flashplayer_uninstall.zip,卸载,下载flashplayer10r12_36_winax_debug.exe,安装,卸载安装后好像谷歌浏览器没影响,然后eclipse修改默认浏览器为ie,window>preferences>general>web browser,选择internet explorer,最后还有,启动tomcat后,必须在mxml上面右键debug运行,打开的ie才会打印trace,直接访问网址是不行的。
如有遗漏请指出
发表评论