Flex4.6+Hibernate3.2 +Spring2.5+tomcat+mySQL _01.docx_第1页
Flex4.6+Hibernate3.2 +Spring2.5+tomcat+mySQL _01.docx_第2页
Flex4.6+Hibernate3.2 +Spring2.5+tomcat+mySQL _01.docx_第3页
Flex4.6+Hibernate3.2 +Spring2.5+tomcat+mySQL _01.docx_第4页
Flex4.6+Hibernate3.2 +Spring2.5+tomcat+mySQL _01.docx_第5页
已阅读5页,还剩34页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

搭建Flex4.6+Hibernate3.2 +Spring2.5+tomcat+mySQL环境1. 安装MyEclipse8.62. 安装FlashBuilder_4_Plugin_LS10.exe3. FlashBuilder安装的过程中需要绑定MyEclipse8.6的路径(绑定的目录下必须有myeclipse.exe文件和dropins文件夹)4. 安装成功后,启动MyEclipse8.6,报错An internal error occurred during: Initializing TargetCfg.java.lang.NullPointerException,解决办法是删掉GenuitecCommonplugins文件夹下面的一个包:mon.http_3.0.3.v201007291200.jar,然后重启MyEclipse8.6。但是发现不能创建Web工程,所以我就把这个包又加到了plugins文件夹下面。就没报错了。(如果MyEclipse8.5中没有Tomcat服务器,就要安装一个Tomcat插件,方法如下:将com.sysdeo.eclipse.tomcat_3.2.1文件夹放到D:programfilesGenuitecCommonplugins,打开D:program filesGenuitecMyEclipse 8.5文件,在最后加上com.sysdeo.eclipse.tomcat,3.2.1,file:/D:/program files/Genuitec/Common/plugins/com.sysdeo.eclipse.tomcat_3.2.1/,4,false重启MyEclipse 8.5.window - preferences - Tomcat 配置一些参数 ,OK!)5. 新建web项目TestProjectJava6. 添加bleazeds支持找到已解压的 bleazeds 文件夹,进入到:blazedsWEB-INF复制flex和lib两个文件夹到TestProjectJava下的webRoot/WEB-INF目录下7. 在web.xml文件中添加代码: flex.messaging.HttpFlexSession MessageBrokerServlet!-MessageBrokerServlet- flex.messaging.MessageBrokerServlet services.configuration.file /WEB-INF/flex/services-config.xml 1 MessageBrokerServlet /messagebroker/*8. 将web工程添加到tomcat中启动tomcat9. 添加Flex工程右键HCS,选择:添加/更改项目类型添加Flex项目类型10.点Next,如下配置注:服务技术选择如下11.点击Finish。13. 到了这个时候基本上已经搭建好Flex+bleazeds的web环境,现在来测试一下1.)新建一个包: web2.) 在包中新一个类:HelloWorld,作用flex的一个远程对象,HelloWorld中的代码如下package web;public class HelloWorld public String sayHelloTo(String name)return Hello +name;3.) 在TestProjectJava/WebRoot/WEB-INF/flex/remoting-config.xml注册这个远程对象 web.HelloWorld 4.) 在TestProjectFlex src下新增包util 并新增RemoteObjectResult.as 和 RemoteObjectUtil.as 并编写TestProjectFlex.mxmlA.RemoteObjectUtil.as 代码如下package utilimport mx.controls.Alert; import mx.rpc.AsyncToken; import mx.rpc.CallResponder; import mx.rpc.Responder; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.AbstractOperation; import mx.rpc.remoting.mxml.RemoteObject; /* * *http:/hackerzhou.me/2011/04/develop-flex-exprience-chapter-one-remote-object.html */public class RemoteObjectUtil extends RemoteObject public static const DEFAULT_DESTINATION:String = UIDataServiceImpl; public function RemoteObjectUtil(destination:String = DEFAULT_DESTINATION) super(destination); public function call(methodName:String, callback:Function, .args):void var method:AbstractOperation = this.getOperation(methodName); /为了方便起见,如果有多个参数的话就把参数包成一个Array,在J2EE端使用Object来获取参数 method.arguments = args; var call:AsyncToken = method.send(); call.userDefinedCallback = callback; call.addResponder(new Responder(resultCallback, faultCallback); public function resultCallback(event:ResultEvent):void var callback:Function = event.token.userDefinedCallback as Function; if (callback != null) var result:RemoteObjectResult = new RemoteObjectResult(); result.error = false; result.resultData = event.result; callback(result); public function faultCallback(event:FaultEvent):void var callback:Function = event.token.userDefinedCallback as Function; if (callback != null) var result:RemoteObjectResult = new RemoteObjectResult(); result.error = true; result.errorMessage = event.fault.toString(); callback(result); B. RemoteObjectResult.as 代码如下package utilimport mx.rpc.events.FaultEvent; public class RemoteObjectResult public var error:Boolean = false; public var errorMessage:String = null; public var resultData:Object = null; C. TestProjectFlex.mxml 代码如下5.) 启动tomcat,等tomcat启动好后,右键单击TestProjectFlex.mxml,选中Run AsWeb应用程序,然后点击测试:到了这一步,flex+bleazeds已经完成14.添加Spring框架,在MyEclipse Java Enterprise视图下的步骤如下:点击TestProjectJava工程MyEclipseAdd Spring Capabilities(本次环境使用的是Spring2.5 )点击Next点击Finish点击Keep Existing15. 添加common,添加SpringFactory.java(网上的):当前结构如下 SpringFactory.java 代码package common;import org.springframework.context.ApplicationContext;import org.springframework.web.context.support.WebApplicationContextUtils;import org.springframework.beans.BeansException;import org.springframework.beans.factory.NoSuchBeanDefinitionException;import flex.messaging.FactoryInstance;import flex.messaging.FlexFactory;import flex.messaging.config.ConfigMap;import flex.messaging.services.ServiceException;/* * This interface is implemented by factory components which provide * instances to the flex messaging framework. To configure flex data services * to use this factory, add the following lines to your services-config.xml * file (located in the WEB-INF/flex directory of your web application). * *<factories> * <factory id=spring class=flex.samples.factories.SpringFactory /> * </factories> * * You also must configure the web application to use spring and must copy the spring.jar * file into your WEB-INF/lib directory. To configure your app server to use spring, * you add the following lines to your WEB-INF/web.xml file: * * <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> * * Then you put your spring bean configuration in WEB-INF/applicationContext.xml (as per the * line above). For example: * * <?xml version=1.0 encoding=UTF-8?> * <!DOCTYPE beans PUBLIC -/SPRING/DTD BEAN/EN /dtd/spring-beans.dtd> * * <beans> * <bean name=weatherBean class=dev.weather.WeatherService singleton=true/> * </beans> * * Now you are ready to define a destination in flex that maps to this existing service. * To do this youd add this to your WEB-INF/flex/remoting-config.xml: * * <destination id=WeatherService> * <properties> * <factory>spring</factory> * <source>weatherBean</source> * </properties> * </destination> * * author Jeff Vroom */public class SpringFactory implements FlexFactory private static final String SOURCE = source; /* * This method can be used to initialize the factory itself. It is called with configuration * parameters from the factory tag which defines the id of the factory. */ public void initialize(String id, ConfigMap configMap) /* * This method is called when we initialize the definition of an instance * which will be looked up by this factory. It should validate that * the properties supplied are valid to define an instance. * Any valid properties used for this configuration must be accessed to * avoid warnings about unused configuration elements. If your factory * is only used for application scoped components, this method can simply * return a factory instance which delegates the creation of the component * to the FactoryInstances lookup method. */ 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() /* * Returns the instance specified by the source * and properties arguments. For the factory, this may mean * constructing a new instance, optionally registering it in some other * name space such as the session or JNDI, and then returning it * or it may mean creating a new instance and returning it. * This method is called for each request to operate on the * given item by the system so it should be relatively efficient. * * If your factory does not support the scope property, it * report an error if scope is supplied in the properties * for this instance. */ 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; 16. 在WEB-INF/flex中的services-config.xml中注册SpringFactory工厂17.在WEB-INF/web.xml中加入对spring的支持 contextConfigLocation applicationContext.xml SpringContextServlet org.springframework.web.context.ContextLoaderServlet 1 SpringLog4jConfigServlet org.springframework.web.util.Log4jConfigServlet web org.springframework.web.servlet.DispatcherServlet 注意:如果此步骤出现异常 可以将头部文件内容删除17添加hibernate1).创建表create table hcs_user( user_id int primary key not null, user_name varchar2(30), real_name varchar2(20), password varchar2(20), sex varchar2(3), birthday varchar2(30), email varchar2(40), address varchar2(50), telephone varchar2(20), qq varchar2(15), authority varchar2(50), remarks varchar2(50);2).切换到MyEclipse Hibernate视图 添加数据源(注:此操作前请提前准备好JDBC的驱动包 如:点击Next,点击Finish3.) 加进hibernate框架,在MyEclipse Java Enterprise视图下的步骤如下:点击TestProjectJava Add HibernateCapabilities (注:Hibernate 3.2)点击 Finish18.添加包,结构如下:19.删除asm-2.2.3.jar20. 利用myeclipse自动生成User.java,User.hbm.xml,UserDAO右击表名,选中Hibernate Reverse Engineering,点击Next 点击NEXT点击Finish21. 把UserDAO放到dao.impl下22. 修改applicationContext.xml(一般系统会自动修改 更新)23.在service.impl添加service类,起名IUserServiceImplpackage service.impl;import model.User;import dao.impl.UserDAO;pu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论