侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

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

技术  /  管理员 发布于 7年前   332

最先下载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,直接访问网址是不行的。
如有遗漏请指出


  • 上一条:
    flex小技巧之加载GIF图片
    下一条:
    Flex 错误(mx.messaging.messages::RemotingMessage)分析
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 2024.07.09日OpenAI将终止对中国等国家和地区API服务(0个评论)
    • 2024/6/9最新免费公益节点SSR/V2ray/Shadowrocket/Clash节点分享|科学上网|免费梯子(0个评论)
    • 国外服务器实现api.openai.com反代nginx配置(0个评论)
    • 2024/4/28最新免费公益节点SSR/V2ray/Shadowrocket/Clash节点分享|科学上网|免费梯子(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2017-09
    • 2018-01
    • 2018-07
    • 2018-08
    • 2018-09
    • 2018-12
    • 2019-01
    • 2019-02
    • 2019-03
    • 2019-04
    • 2019-05
    • 2019-06
    • 2019-07
    • 2019-08
    • 2019-09
    • 2019-10
    • 2019-11
    • 2019-12
    • 2020-01
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-12
    • 2024-02
    • 2024-04
    • 2024-05
    • 2024-06
    • 2025-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客