手把手教你使用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填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,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,直接访问网址是不行的。
如有遗漏请指出

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


本文从从Bitcask存储模型讲起,谈轻量级KV系统设计与实现。从来没有最好的K-V系统,只有最适合应用业务实际场景的系统,做任何的方案选择,要结合业务当前的实际情况综合权衡,有所取有所舍。
内部的放到gitlab pages的博客,需要统计PV,不蒜子不能准确统计,原因在于gitlab的host设置了strict-origin-when-cross-origin, 导致不蒜子不能正确获取referer,从而PV只能统计到网站的PV。 为了方便统计页面的PV,这里简单的写了一个java程
PCM 自然界中的声音非常复杂,波形极其复杂,通常我们采用的是脉冲代码调制编码,即PCM编码。PCM通过抽样、量化、编码三个步骤将连续变化的模拟信号转换为数字编码。 采样率 采样频率,也称为采样速度或者采样率,定义了每秒从连续信号中提取并组成离散信号的采样个数,它用赫兹(Hz)来表示。采样频率的倒数
本文介绍如何离线生成sst并在线加载,提供一种用rocksdb建立分布式kv系统替换mongodb的思路
验证用户输入是否正确是我们应用程序中的常见功能。Spring提供了`@Valid`和@`Validated`两个注解来实现验证功能,本文详细介绍 [@Valid]和[@Validated]注解的区别 。
引入pdf2dom &lt;dependency&gt; &lt;groupId&gt;net.sf.cssbox&lt;/groupId&gt; &lt;artifactId&gt;pdf2dom&lt;/artifactId&gt; &lt;version&gt;1.8&lt;/version&
grafana 是一款非常优秀的可视化报表工具,有设计精良的可视化工具,今天来聊一聊如何将grafana集成到自己的应用中。 原理是: grafana允许iframe访问,开启auth.proxy, java 后端鉴权后代理grafana 前端通过iframe访问后端代理过的grafana graf
介绍 Call Graph是一款IDEA插件,用于可视化基于IntelliJ平台的IDE的函数调用图。 这个插件的目标是让代码更容易理解,有助于读懂和调试代码。当前只支持Java。针对Typescript、Javascript或Python工具,可以使用作者的另外一款工具Codemap(https:
原理 通过线程安全findAndModify 实现锁 实现 定义锁存储对象: /** * mongodb 分布式锁 */ @Data @NoArgsConstructor @AllArgsConstructor @Document(collection = &quot;distributed-loc
Singleton 单例模式 单例模式是确保每个应用程序只存在一个实例的机制。默认情况下,Spring将所有bean创建为单例。 你用@Autowired获取的bean,全局唯一。 @RestController public class LibraryController { @Autowired
pipeline 分布式任务调度器 目标: 基于docker的布式任务调度器, 比quartzs,xxl-job 更强大的分布式任务调度器。 可以将要执行的任务打包为docker镜像,或者选择已有镜像,自定义脚本程序,通过pipeline框架来实现调度。 开源地址: https://github.c
python训练的模型,转换为onnx模型后,用python代码可以方便进行推理,但是java代码如何实现呢? 首先ONNX 推理,可以使用`onnxruntime` ```xml com.microsoft.onnxruntime onnxruntime 1.15.1 ``` 另外,训练的模型需要
要获取内网地址,可以尝试连接到10.255.255.255:1。如果连接成功,获取本地套接字的地址信息就是当前的内网IP。 python实现: ```python import socket def extract_ip(): st = socket.socket(socket.AF_INET, s
为什么要有索引 gremlin 其实是一个逐级过滤的运行机制,比如下面的一个简单的gremlin查询语句: g.V().hasLabel(&quot;label&quot;).has(&quot;prop&quot;,&quot;value&quot;) 运行原理就是: 找出所有的顶点V 然后过滤出
最近在分析一个应用中的某个接口的耗时情况时,发现一个看起来极其普通的对象创建操作,竟然每次需要消耗 8ms 左右时间,分析后发现这个对象可以通过对象池模式进行优化,优化后此步耗时仅有 0.01ms。
点赞再看,动力无限。Hello world : ) 微信搜「 程序猿阿朗 」。 本文 Github.com/niumoo/JavaNotes 和 未读代码网站 已经收录,有很多知识点和系列文章。 此篇文章介绍 Java JMX 技术的相关概念和具体的使用方式。 当前文章属于Java 性能分析优化系列
如何将Java JAR 转化为 win/mac/linux 独立可执行程序?不需要预装 JRE 运行?
点赞再看,动力无限。 微信搜「 程序猿阿朗 」。 本文 Github.com/niumoo/JavaNotes 和 未读代码博客 已经收录,有很多知识点和系列文章。 Java 19 在2022 年 9 月 20 日正式发布,Java 19 不是一个长期支持版本,直到 2023 年 3 月它将被 JD
点赞再看,动力无限。Hello world : ) 微信搜「 程序猿阿朗 」。 本文 Github.com/niumoo/JavaNotes 和 未读代码博客 已经收录,有很多知识点和系列文章。 前言 Java 反编译,一听可能觉得高深莫测,其实反编译并不是什么特别高级的操作,Java 对于 Cla
JSON 对于开发者并不陌生,如今的 WEB 服务、移动应用、甚至物联网大多都是以 **JSON** 作为数据交换的格式。学习 JSON 格式的操作工具对开发者来说是必不可少的。这篇文章将介绍如何使用 **Jackson** 开源工具库对 JSON 进行常见操作。