• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Flex > 手把手教你使用flex eclipse整合spring

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

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了手把手教你使用flex eclipse整合spring等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

最先下载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>
</div>

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>
</div>

其中

<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>
</div>

result对应的是java方法调用的回调函数
建一个普通java类

package com.hongbo;

public class Hello {

 public String sayHello(String name){
  System.out.println("------------------------------------");
  return "Hello First Demo " + name;
 }
}
</div>

这样就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>
</div>

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>
</div>

3:WEB-INF/flex/service-config.xml加入

<factories>
   <factory id="spring" class="com.hongbo.SpringFactory" /> 
 </factories>
</div>

添加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 ServiceExcep



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

相关文章

  • 2017-05-11flex中使用css样式修改TextArea滚动条的皮肤代码
  • 2017-05-11Flex 基于数据源的Menu Tree实现代码
  • 2017-05-11Flex弹出窗口请求Action函数示例
  • 2017-05-11flex actionScript时间处理相加返回相加后的date
  • 2017-05-11flex不显示GIF图片问题的另类解决方法
  • 2017-05-11flex与js通信与彼此之间的互调整理(二)
  • 2017-05-11flex通过java后台获取ip和pcname示例代码
  • 2017-05-11Flex中怎么给表格中的滚动条定位避免刷新回到原处
  • 2017-05-11Flex上传本地图片并提前浏览的实现方法
  • 2017-05-11FLEX 获取DataGrid行号和列号示例代码

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • flex通过js获取ip和pcname示例代码
    • Flex调Javascript打开新窗口示例代码
    • Flex 自定义DataGrid实现根据条目某一属性值改变背景颜色
    • Flex Label控件竖排显示文字的实现代码
    • Flex DataGrid自动编号示例
    • Flex 遍历Object键和值的示例代码
    • Flex中TextInput组件设置限制某些字符的输入的方法
    • 手把手教你使用flex eclipse整合spring
    • Flex中对表格某列的值进行数字格式化并求百分比添加%
    • flex调用webservice中的自定义类的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有