---
title: "Flex4+Spring3+Hibernate3+BlazeDS整合笔记"
author: "cwsot"
date: "2012-07-01T09:41:34Z"
tags: []
categories: ["非技术"]
slug: "flex4-spring3-hibernate3-blazeds"
draft: false
lastmod: "2012-07-01T09:41:34Z"
id: 1572714
url: "https://cwsot.iteye.com/blog/1572714"
---

普通Java Web工程流行使用ssh框架，而当前台使用Flex制作的时候，后台就不需要用Struts了，通过使用BlazeDS远程方法调用即可。 
　　首先，新建Java Web工程，然后添加Flex项目，详情见通过J2EE Web工程添加Flex项目，进行BlazeDS开发  。 
　　随后，导入Jar包，flex相关的jar包在添加Flex项目的时候已经导入，这里主要是导入Spring和Hibernate相关 的jar包以及spring和flex集成的jar包，我用的是spring 3.0.3和hibernate 3.2.1。 下面是lib列表： 
　　antlr-2.7.6.jar     asm-2.2.3.jar 
　　asm-commons-2.2.3.jar 
　　asm-util-2.2.3.jar 
　　aspectjlib.jar 
　　aspectjrt.jar 
　　aspectjweaver.jar 
　　backport-util-concurrent.jar 
　　c3p0-0.9.1.jar 
　　cfgatewayadapter.jar 
　　cglib-nodep-2.1_3.jar 
　　com.springsource.edu.emory.mathcs.backport-3.0.0.j ar 
　　com.springsource.net.sf.cglib-2.2.0.jar 
　　com.springsource.org.aopalliance-1.0.0.jar 
　　commons-codec-1.3.jar 
　　commons-collections-3.1.jar 
　　commons-httpclient-3.0.1.jar 
　　commons-io-1.4.jar 
　　commons-lang-2.3.jar 
　　commons-logging.jar 
　　dom4j-1.6.1.jar 
　　ehcache-1.2.3.jar 
　　flex-messaging-common.jar 
　　flex-messaging-core.jar 
　　flex-messaging-opt.jar 
　　flex-messaging-proxy.jar 
　　flex-messaging-remoting.jar 
　　flex-rds-server.jar 
　　freemarker-2.3.15.jar 
　　hibernate-commons-annotations-3.2.0.Final.jar 
　　hibernate-core-3.5.4-Final.jar 
　　hibernate-jpa-2.0-api-1.0.0.Final.jar 
　　jackson-lgpl-0.9.5.jar 
　　javassist.jar 
　　jta-1.1.jar 
　　log4j-1.2.15.jar 
　　mysql-connector-java-5.1.13-bin.jar 
　　org.springframework.aop-3.0.3.RELEASE.jar 
　　org.springframework.asm-3.0.3.RELEASE.jar 
　　org.springframework.aspects-3.0.3.RELEASE.jar 
　　org.springframework.beans-3.0.3.RELEASE.jar 
　　org.springframework.context-3.0.3.RELEASE.jar 
　　org.springframework.context.support-3.0.3.RELEASE. jar 
　　org.springframework.core-3.0.3.RELEASE.jar 
　　org.springframework.expression-3.0.3.RELEASE.jar 
　　org.springframework.flex-1.0.3.RELEASE.jar 
　　org.springframework.instrument-3.0.3.RELEASE.jar 
　　org.springframework.instrument.tomcat-3.0.3.RELEAS E.jar 
　　org.springframework.jdbc-3.0.3.RELEASE.jar 
　　org.springframework.jms-3.0.3.RELEASE.jar 
　　org.springframework.orm-3.0.3.RELEASE.jar 
　　org.springframework.oxm-3.0.3.RELEASE.jar 
　　org.springframework.test-3.0.3.RELEASE.jar 
　　org.springframework.transaction-3.0.3.RELEASE.jar 
　　org.springframework.web-3.0.3.RELEASE.jar 
　　org.springframework.web.portlet-3.0.3.RELEASE.jar 
　　org.springframework.web.servlet-3.0.3.RELEASE.jar 
　　org.springframework.web.struts-3.0.3.RELEASE.jar 
　　slf4j-api-1.5.8.jar 
　　修改配置文件，web.xml，其中最重要的是修改原先MessegeBroker Servlet，改为由Spring web应用前端控制器处理所有请求。 Flex配置xml-->  flex  org.springframework.web.servlet.DispatcherServlet   contextConfigLocation  /WEB-INF/config/flex-application-config.xml   1    flex /messagebroker/*  配置 flex-application-config.xml，注意增加的几个命名空间，需要包org.springframework.flex-1.0.3.RELEASE.jar ，同时在这个文件里定义了bean，在mxml里面会引用到：  flex="http://www.springframework.org/schema/ flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan ce" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring -beans-2.5.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring- flex-1.0.xsd">  flex:message-broker/>     flex:remoting-destination />    hibernate的配置，用到c0p0.jar，               org.hibernate.dialect.MySQLDialect   true   true   false      sample/dao/User.hbm.xml           test.mxml，这里主要是定义和调用远程对象，远程对象的bean在上面的flex-application-config.xml里面有定义，调用类sample.Test.java中的createUser方法。  flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">      RemoteObject id="ro" destination="test" result="resulth(event);" fault="faulth(event);" />