Flex与Spring集成【转】

本文介绍如何将Adobe Flex与Spring框架集成,实现富互联网应用程序的快速开发。通过配置Spring工厂,Flex能够直接调用Spring管理的Java对象,简化了前后端交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

来源: http://coenraets.org/flex-spring

What is Spring?Spring is one of the most popular Java frameworks. The foundation ofthe Spring framework is a lightweight component container thatimplements the Inversion of Control (IoC) pattern.
Using an IoC container, components don’t instantiate or even look uptheir dependencies (the objects they work with). The container isresponsible for injecting those dependencies when it creates thecomponents (hence the term “Dependency Injection” also used to describethis pattern).
The result is looser coupling between components. The Spring IoCcontainer has proven to be a solid foundation for building robustenterprise applications. The components managed by the Spring IoCcontainer are called Spring beans.
The Spring framework includes several other modules in addition toits core IoC container. These modules are not covered in this documenteven though we will be using the Spring JDBC abstraction framework inexamples 2 and 3 below. More information on the Spring framework can befound at http://www.springframework.org.
What is Flex? Flex provides a complete solution for building Rich Internet Applications. The Flex programming model is made of:
ActionScript, an ECMAScript compliant,object-oriented programming model. With some syntactical differences,ActionScript looks and feels similar to Java, and supports the sameobject-oriented constructs: packages, classes, inheritance, interfaces,strong (but also dynamic) typing etc. MXML: an XML-based language that provides anabstraction on top of ActionScript, and allows parts of an application(typically the View) to be built declaratively. An extensive set of class libraries. The online API documentation is available here in a Javadoc-like format. The Flex source code (.mxml and .as files) is compiled into Flashbytecode (.swf) that is executed at the client-side by the Flashvirtual machine using a Just-In-Time compiler.
A complete discussion of Flex is beyond the scope of this document. You can find more information at http://www.adobe.com/products/flex.
How does Flex access back-end systems?When writing Flex applications, you can access back-end systems using four different strategies:
You can use the HTTPService component to send HTTPrequests to a server, and consume the response. Although theHTTPService is typically used to consume XML, it can be used to consumeother types of responses. The Flex HTTPService is similar to theXMLHttpRequest component available in Ajax. You can use the WebService component to invoke SOAP-based web services. You can use the RemoteObject component to directlyinvoke methods of Java objects deployed in your application server, andconsume the return value. The return value can be a value of aprimitive data type, an object, a collection of objects, an objectgraph, etc. In distributed computing terminology, this approach isgenerally referred to as “remoting”. This is also the terminology used in Spring to describe how different clients can access Spring beans remotely. In addition to the RPC-type services described above, the Flex Data Management Servicesprovide an innovative and virtually code-free approach to synchronizedata between the client application and the middle-tier. In this document, we focus on the Remoting (3) and Data ManagementServices (4) approaches described above because they enable thetightest integration with Spring. There is no need to transform data,or to expose services in a certain way: the Flex application worksdirectly with the beans registered in the Spring IoC container.
How does Flex access Spring beans? So, if Flex clients can remotely access Java objects, and if Springbeans are Java objects, aren’t we all set and ready to start accessingSpring beans from Flex clients? Almost… There is one simple element toconfigure.
The whole idea behind Spring IoC is to let the container instantiatecomponents (and inject their dependencies). By default, however,components accessed remotely by a Flex client are instantiated by Flexdestinations at the server-side. The key to the Flex/Spring integrationis therefore to configure the Flex destinations to let the Springcontainer take care of instantiating Spring beans. The Flex DataServices support the concept of factory to enable this type of customcomponent instantiation. The role of a factory is simply to provideready-to-use instances of components to a Flex destination (instead ofletting the Flex destination instantiate these components itself).
The supporting files available with this document include a factoryclass (SpringFactory) that provides Flex destinations with fullyinitialized (dependency-injected) instances of Spring beans. Note: TheSpringFactory was developed by Jeff Vroom (Flex Data Servicesarchitect) and is also available on Adobe Exchange.
The remaining of this article describes how to configure your webapplication to use Flex and Spring, how to configure the SpringFactory, and how to put the pieces together and start invoking Springbeans from Flex applications.
Setting Up your Web Application to Use Flex and SpringStep 1: Install the supporting files Download flex-spring.zip here Expand flex-spring.zip flex-spring.zip includes the Spring factory as well as the supporting files for the examples below.
Step 2: Install Flex Data ServicesTo use the Remoting and Data Management Services data accessstrategies described above, you need to install the Flex Data Services.If you haven’t already done so, you can download the Flex Data Serviceshere, and follow the installation instructions.
The installation process will install three web applications (flex,samples, and flex-admin). You can use either the flex or samples webapplication to run the examples below.
You can read more information on the installation process here: http://www.adobe.com/support/documentation/en/flex/2/install.html#installingfds2
Step 3: Install SpringNote: A complete discussion of the Spring installation process is beyond the scope of this article. Refer to http://www.springframework.org for more information. The steps below describe a basic configuration that is sufficient for the purpose of this article.
Download the Spring framework (version 2.0) at http://www.springframework.org/download (the version without dependencies is sufficient to complete the examples in this article).
Note: The examples below have been developed and tested using Spring2.0. However the integration approach described in this document (andthe SpringFactory class) should work fine using Spring 1.2.8 (some ofthe examples might not work because they use Spring 2.0 features).
Expand the downloaded file Locate spring.jar in the dist directory and copy it in the {context-root}\WEB-INF\lib directory of your web application Modify the web.xml file of your web application. Add the context-param and listener definitions as follows:<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Step 4: Register the Spring Factory Copy SpringFactory.class andSpringFactory$SpringFactoryInstance.class fromflex-spring-sdk\bin\flex\samples\factories to{context-root}\WEB-INF\classes\flex\samples\factories Register the Spring factory in {context-root}\WEB-INF\flex\services-config.xml:<factories>
<factory class="flex.samples.factories.SpringFactory" id="spring">
</factory></factories>
Example 1: Mortgage Calculator Using Flex RemotingThis first application is intentionally simplistic in itsfunctionality to provide an uncluttered example of wiring Spring beanstogether and invoking them from a Flex application.
Step 1: Copy the application files Copy RateFinder.class, SimpleRateFinder.class, and Mortgage.classfrom flex-spring-sdk\bin\flex\samples\spring\mortgage to{context-root}\WEB-INF\classes\flex\samples\spring\mortgage Copy mortgage.mxml from flex-spring-sdk\flex\mortgage to {context-root}\mortgage Step 2: Register Spring Beans Before registering the Spring beans for this application, openRateFinder.java, SimpleRateFinder.java and Mortgage.java inflex-spring-sdk\src\flex\samples\spring\mortgage to familiarizeyourself with the source code. Notice that Mortgage has a dependency toa RateFinder object. Mortgage doesn’t instantiate a RateFinder objectitself, doesn’t lookup up for a RateFinder object, and doesn’t evenknow the exact type of the object it will be dealing with (RateFinderis an inteface). An instance of a class implementing the RateFinderinterface will be injected by the container (using the setRateFindermethod) when it instantiates the component. If it doesn’t already exist, create a file named applicationContext.xml in {context-root}\WEB-INF. Register the rateFinderBean and mortgageBean beans in applicationContext.xml as follows:


<beans>

<bean class="flex.samples.spring.mortgage.SimpleRateFinder" id="rateFinderBean">

<bean class="flex.samples.spring.mortgage.Mortgage" id="mortgageBean">
<property ref="rateFinderBean" name="rateFinder">
</property>

</bean></bean></beans>
Notice that in the mortgageBean definition, we tell the containerhow to inject the rateFinder dependency: the rateFinder property ismapped to rateFinderBean which defines an instance of theSimpleRateFinder class. Step 3: Configure the Flex Remoting Destination Open remoting-config.xml in {context-root}\WEB-INF\flex. Add a mortgageService destination as follows: <destination id="mortgageService">
<properties>
<factory>spring</factory>
<source>mortgageBean</source>
</properties>
</destination>
Notice that we use the spring factory defined above (see “Registerthe Spring Factory”), and we provide the name of the Spring bean asdefined in applicationContext.xml as the source. Step 4: Run the Client Application Open {context-root}\mortgage\MortgageCalc.mxml in a code editor tofamiliarize yourself with the application. Notice that the RemoteObjectdestination is the mortgageService destination defined above. Open a browser, acceshttp://host:port/context-root/mortgage/MortgageCalc.mxml, and test theapplication: Enter a loan amount and click “Calculate” to get themonthly payment for a 30 year mortgage. Note: that there is a delay the first time you access an applicationin this manner. This is because we are using the web compiler whichcompiles your application into bytecode the first time it is accessed(similar to the JSP compilation model). Subsequent requests to the sameapplication will be much faster since the application is alreadycompiled. In a production environment, you would typically deployapplications that have already been compiled using the Flex compileravailable as a command-line utility or fully integrated in FlexBuilder(the Eclipse-based development environment for Flex).
Depending on your configuration, you may need to increase the heap size of your application server’s JVM to use the web compiler.This would not be required in a production environment since youtypically don’t use the web compiler. If you get ajava.lang.OutOfMemoryError exception while trying to access a samplefor the first time, you must increase your heap size. Alternatively,you can compile the application using FlexBuilder or the command linecompiler.

Example 2: Store/Inventory Management using Flex RemotingThis second example is more sophisticated and includes databaseconnectivity. To keep the application simple and avoid dependencies onother products or frameworks, the Spring JDBC abstraction framework isused to access the database. You could use the Spring support for ORMdata access (using Hibernate, JDO, Oracle TopLink, iBATIS, or JPA) asan alternative: the specific Spring data access strategy you choose hasno impact on the Flex/Spring integration. We use an embedded HSQLDBdatabase: the only installation requirement is to copy the HSQLDBdriver in your web application classpath (see below). The applicationhas two modules: a database maintenance module, and a customer-facingproduct catalog with filtering capabilities.
Step 1: Copy the application files Copy hsqldb.jar to {context-root}\WEB-INF\lib. You can download the hsqldb driver at http://www.hsqldb.org/. Copy ProductDAO.class, SimpleProductDAO.class,SimpleProductDAO$1.class, and Product.class fromflex-spring-sdk\bin\flex\samples\spring\store to{context-root}\WEB-INF\classes\flex\samples\spring\store Copy admin.mxml, ProductForm.mxml, store.mxml, Thumb.mxml,AnimatedTileList.as, Product.as, logo.jpg, store.css and the picdirectory from flex-spring-sdk\flex\store to {context-root}\store Step 2: Register Spring Beans Before registering the Spring beans for this application, openProductDAO.java, SimpleProductDAO.java and Product.java inflex-spring-sdk\src\flex\samples\spring\store to familiarize yourselfwith the source code. Notice that SimpleProductDAO extendsorg.springframework.jdbc.core.support.JdbcDaoSupport. JdbcDaoSupporthas a dependency to a javax.sql.DataSource object (javax.sql.DataSourceis an interface). Register the dataSource and productDAOBean beans in applicationContext.xml as follows: <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property value="org.hsqldb.jdbcDriver" name="driverClassName">
<property value="jdbc:hsqldb:/flex-spring-sdk/db/store" name="url">
<property value="sa" name="username">
<property value="" name="password">
</property>

<bean class="flex.samples.spring.store.SimpleProductDAO" id="productDAOBean">
<property ref="dataSource" name="dataSource">
</property> </bean></property> </property> </property> </bean>
Note: If you didn’t unzip flex-spring-sdk in your root directory, adjust the JDBC url accordingly. Step 3: Configure the Flex Remoting Destination Open remoting-config.xml in {context-root}\WEB-INF\flex. Add the productService destination as follows: <destination id="productService">
<properties>
<factory>spring</factory>
<source>productDAOBean</source>
</properties>
</destination>
Step 4: Run the Client ApplicationTest the database maintenance module:
Open {context-root}\store\admin.mxml in a code editor and familiarize yourself with the application. Open a browser, access http://host:port/context-root/store/admin.mxml, and test the application. Test the store module:
Open {context-root}\store\store.mxml in a code editor and familiarize yourself with the application. Open a browser, access http://host:port/context-root/store/store.mxml, and test the application. Example 3: Data Management ServicesIn addition to the RPC services used in examples 1 and 2 above, theFlex Data Management Services provide an innovative and very productiveapproach to synchronize data between the client and the middle-tier.The Flex Data Management Services consist of a client-side API andserver-side services:
At the client-side, "managed objects" keep track of changes made tothe data, and notify the back-end of these changes. You don’t have tokeep track of changes made to the data, nor do you have to invokeremote services to notify the back-end of the changes (create, update,delete) made at the client side. At the server-side, the Data Service receives the list of changesand passes it to your server-side persistence components. The DataService also pushes the changes to other clients. This application provides an example of using the Flex Data Management Services with the Spring IoC container.
Note: The Flex Data Management Services leverage the JavaTransaction API (JTA). If you are using Tomcat, or another servletcontainer that doesn’t provide a full implementation of the J2EE stack,you have to install a JTA implementation such as JOTM to run thisexample. Click here for more information.
Step 1: Copy the application files Copy ProductAssembler.class fromflex-spring-sdk\bin\flex\samples\spring\store to{context-root}\WEB-INF\classes\flex\samples\spring\store Copy dms.mxml and Product.as from flex-spring-sdk\flex\dms to {context-root}\dms Step 2: Register Spring Beans Open ProductAssembler.java in a code editor. Notice that ProductAssembler has a dependency to a ProductDAO object. Register the productAssemblerBean in applicationContext.xml as follows:<bean class="flex.samples.spring.store.ProductAssembler" id="productAssemblerBean">
<property ref="productDAOBean" name="productDAO">
</property> </bean>
Step 3: Configure the Flex Data Management Services Destination Open data-management-config.xml in {context-root}\WEB-INF\flex. Add the product destination as follows:<destination id="product">
<adapter ref="java-dao">
<properties>
<source>productAssemblerBean</source>
<factory>spring</factory>

<identity property="productId">
</identity>

</properties> </adapter></destination>
Step 4: Run the Client Application Open {context-root}\dms\dms.mxml in a code editor and familiarize yourself with the application. Open a browser, access http://host:port/context-root/dms/dms.mxml, and test the application.
【基于QT的调色板】是一个使用Qt框架开发的色彩选择工具,类似于Windows操作系统中常见的颜色选取器。Qt是一个跨平台的应用程序开发框架,广泛应用于桌面、移动和嵌入式设备,支持C++和QML语言。这个调色板功能提供了横竖两种渐变模式,用户可以方便地选取所需的颜色值。 在Qt中,调色板(QPalette)是一个关键的类,用于管理应用程序的视觉样式。QPalette包含了一系列的颜色角色,如背景色、前景色、文本色、高亮色等,这些颜色可以根据用户的系统设置或应用程序的需求进行定制。通过自定义QPalette,开发者可以创建具有独特视觉风格的应用程序。 该调色板功能可能使用了QColorDialog,这是一个标准的Qt对话框,允许用户选择颜色。QColorDialog提供了一种简单的方式来获取用户的颜色选择,通常包括一个调色板界面,用户可以通过滑动或点击来选择RGB、HSV或其他色彩模型中的颜色。 横渐变取色可能通过QGradient实现,QGradient允许开发者创建线性或径向的色彩渐变。线性渐变(QLinearGradient)沿直线从一个点到另一个点过渡颜色,而径向渐变(QRadialGradient)则以圆心为中心向外扩散颜色。在调色板中,用户可能可以通过滑动条或鼠标拖动来改变渐变的位置,从而选取不同位置的颜色。 竖渐变取色则可能是通过调整QGradient的方向来实现的,将原本水平的渐变方向改为垂直。这种设计可以提供另一种方式来探索颜色空间,使得选取颜色更为直观和便捷。 在【colorpanelhsb】这个文件名中,我们可以推测这是HSB(色相、饱和度、亮度)色彩模型相关的代码或资源。HSB模型是另一种常见且直观的颜色表示方式,RGB或CMYK模型不同,它以人的感知为基础,更容易理解。在这个调色板中,用户可能可以通过调整H、S、B三个参数来选取所需的颜色。 基于QT的调色板是一个利用Qt框架和其提供的色彩管理工具,如QPalette、QColorDialog、QGradient等,构建的交互式颜色选择组件。它不仅提供了横竖渐变的色彩选取方式,还可能支持HSB色彩模型,使得用户在开发图形用户界面时能更加灵活和精准地控制色彩。
标题基于Spring Boot的二手物品交易网站系统研究AI更换标题第1章引言阐述基于Spring Boot开发二手物品交易网站的研究背景、意义、现状及本文方法创新点。1.1研究背景意义介绍二手物品交易的市场需求和Spring Boot技术的适用性。1.2国内外研究现状概述当前二手物品交易网站的发展现状和趋势。1.3论文方法创新点说明本文采用的研究方法和在系统设计中的创新之处。第2章相关理论技术介绍开发二手物品交易网站所涉及的相关理论和关键技术。2.1Spring Boot框架解释Spring Boot的核心概念和主要特性。2.2数据库技术讨论适用的数据库技术及其在系统中的角色。2.3前端技术阐述后端配合的前端技术及其在系统中的应用。第3章系统需求分析详细分析二手物品交易网站系统的功能需求和性能需求。3.1功能需求列举系统应实现的主要功能模块。3.2性能需求明确系统应满足的性能指标和安全性要求。第4章系统设计实现具体描述基于Spring Boot的二手物品交易网站系统的设计和实现过程。4.1系统架构设计给出系统的整体架构设计和各模块间的交互方式。4.2数据库设计详细阐述数据库的结构设计和数据操作流程。4.3界面设计实现介绍系统的界面设计和用户交互的实现细节。第5章系统测试优化说明对系统进行测试的方法和性能优化的措施。5.1测试方法步骤测试环境的搭建、测试数据的准备及测试流程。5.2测试结果分析对测试结果进行详细分析,验证系统是否满足需求。5.3性能优化措施提出针对系统性能瓶颈的优化建议和实施方案。第6章结论展望总结研究成果,并展望未来可能的研究方向和改进空间。6.1研究结论概括本文基于Spring Boot开发二手物品交易网站的主要发现和成果。6.2展望改进讨论未来可能的系统改进方向和新的功能拓展。
1. 用户权限管理模块 角色管理: 学生:查看个人住宿信息、提交报修申请、查看卫生检查结果、请假外出登记 宿管人员:分配宿舍床位、处理报修申请、记录卫生检查结果、登记晚归情况 管理员:维护楼栋房间信息、管理用户账号、统计住宿数据、发布宿舍通知 用户操作: 登录认证:对接学校统一身份认证(模拟实现,用学号 / 工号作为账号),支持密码重置 信息管理:学生完善个人信息(院系、专业、联系电话),管理员维护所有用户信息 权限控制:不同角色仅可见对应功能(如学生无法修改床位分配信息) 2. 宿舍信息管理模块 楼栋房间管理: 楼栋信息:名称(如 "1 号宿舍楼")、层数、性别限制(男 / 女 / 混合)、管理员(宿管) 房间信息:房间号(如 "101")、户型(4 人间 / 6 人间)、床位数量、已住人数、可用状态 设施信息:记录房间内设施(如空调、热水器、桌椅)的配置完好状态 床位管理: 床位编号:为每个床位设置唯一编号(如 "101-1" 表示 101 房间 1 号床) 状态标记:标记床位为 "空闲 / 已分配 / 维修中",支持批量查询空闲床位 历史记录:保存床位的分配变更记录(如从学生 A 调换到学生 B 的时间原因) 3. 住宿分配调整模块 住宿分配: 新生分配:管理员导入新生名单后,宿管可按专业集中、性别匹配等规则批量分配床位 手动分配:针对专业、复学学生,宿管手动指定空闲床位并记录分配时间 分配结果公示:学生登录后可查看自己的宿舍信息(楼栋、房间号、床位号、室友列表) 调整管理: 调宿申请:学生提交调宿原因(如室友矛盾、身体原因),选择意向宿舍(需有空位) 审批流程:宿管审核申请,通过后执行床位调换,更新双方住宿信息 换宿记录:保存调宿历史(申请人、原床位、新床位、审批人、时间) 4. 报修安全管理模块 报修管理: 报修提交:学生选择宿舍、设施类型(如 "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值