javaflex+spring+hibernate详细配置文档.doc_第1页
javaflex+spring+hibernate详细配置文档.doc_第2页
javaflex+spring+hibernate详细配置文档.doc_第3页
javaflex+spring+hibernate详细配置文档.doc_第4页
javaflex+spring+hibernate详细配置文档.doc_第5页
已阅读5页,还剩31页未读 继续免费阅读

下载本文档

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

文档简介

配置flex+bleazeds+spring+hibernate准备:我个人开发时的配置:MYSQL:MySQL 5.0JDK: j2sdk-TOMCAT:tomcat-5.0.28ECLIPSE:eclipse-3.2MYECLIPSE插件: MyEclipse-5.0Flex: FB3_WWEJ_Plugin.exe BLEAZEDS:BlazeDS /wiki/display/blazeds/Release+Builds,它有三个版本,其中Turnkey版内置了Tomcat和 Flex 3 SDK,还包含blazeds.war、ds-console.war和samples.war,建议初学者使用;Binary Distribution版只包括blazeds.war,此为最简配置;而Source则包含blazeds的Java源代码,想做二次开发就下载这个。安装:一:安装mysql,jdk,tomcat,eclipse,myeclipse并正确配置环境变量。二:安装flex31. 首先下载安装Eclipse 3.3 解压到 D:Program Fileseclipse 到算安装成功了.2. 下载安装Flex Builder 3.0/Applications/Flex/FlexBuilder/3/FB3_WWEJ_Plugin.exe1. 指定 Flex Builder 3.0 安装路径为D:Program FileseclipseFlex Builder,进下一步. (你也可设为其它目录,但不要这样:D:Program Fileseclipse)2. 指定 Eclipse 安装路径为 D:Program Fileseclipse 进下一步.3. 选择是否安装浏览器 Flash Plyer 9 插件(可选安装)安装要花一点时间.大家慢慢等待.出现一些提示你不用管它.等安装完后运行 Eclipse.exe 你是看不到 Flex的.往下看我会帮你解决这个问题_3. 绿化Flex Builder 这是重点.1. 把D:Program FileseclipseFlex Buildercom.adobe.flexbuilder.update.site下的 plugins、features、site.xml复制到 D:Program Fileseclipse (如果你的eclipse目录已经有一个site.xml 你只要把两个文件的feature节内容合并就好了.)2. 把D:Program FileseclipseFlex Buildereclipse下的 plugins、features(如果有的话,这是Eclipse的一些更新)复制到 D:Program Fileseclipse3. 把D:Program FileseclipseFlex Buildersdks 复制到D:Program FileseclipseOK,Flex Builder安装完成,接下来就是启动Elipse我们现在已经可以找到Flex了.但还没完,请往下看.4. 进行Flex的配置.在Eclipse中.点击-Window-Preferences-Flex-Installed Flex SDKs修改Flex SDKs 2.0 和 Flex SDKs 3.0的路径点Apply让设置成效.重启Eclipse.你就可以开发Flex了.5. 现在你的Flex已经开始工作了.但之前安装的Flex Builder怎么办呢.哈哈.运行这个D:Program FileseclipseFlex BuilderUninstall Adobe Flex Builder 3 Plug-inUninstall Adobe Flex Builder 3 Plug-in.exe就可以了.三:bleazeds解压到任何一个地方就可以,主要用到里面的flex文件夹和lib文件夹HELLO WORLD示例:1. 建立数据表CREATE TABLE user ( UserID int(11) NOT NULL auto_increment, UserName varchar(20) default NULL, Password varchar(20) default NULL, Email varchar(20) default NULL, PRIMARY KEY (UserID) ENGINE=InnoDB DEFAULT CHARSET=gb2312;2. 插入测试数据3. 搭配flex+bleazeds的web项目1.新建web项目MyFirstFSH按NEXT进入下一步点击FINISH2.添加bleazeds支持1.找到已解压的 bleazeds 文件夹,进入到:blazedsWEB-INF复制flex和lib两个文件夹到MyFirstFSH下的webRoot/WEB-INF目录下2.在web.xml文件中添加代码: flex.messaging.HttpFlexSession MessageBrokerServlet flex.messaging.MessageBrokerServlet services.configuration.file /WEB-INF/flex/services-config.xml 1 MessageBrokerServlet /messagebroker/*将web工程添加到tomcat中按3.添加flex工程 1.右键MyFirtstFSH,选择:Flex Project Nature-Add Flex Project Nature注:选择J2EE,作用LCDS远程对象Root folder:选择刚才Deploy的工程路径Root URL:TOMCAT服务器的启动路径Context root :编译后的FLEX文件保存路径Output folder:工程 重构后FLEX文件的输出路径点击Finish完成2配置Flex 项目属性在Flex视图下,右键 properties打开项目属性设置对话框.选择 “Flex Build Path”,出现以下对话框:Output folder:工程FLEX文件的输出路径Output folder URL:工程在TOMCAT服务器的启动路径选择 “Flex Compiler”,出现以下对话框:选择你当前用的FLEX SDK(如何你前面步骤配置好的话就不会出错了!)点击Apply应用选择 “Flex Server”,出现以下对话框:Context root:是你的工程的根目录点击OK完成设置这时会出现错误提示:右键“错误”信息,Recreate 3.到了这个时候基本上已经搭建好flex+bleazeds的web环境,现在来测试一下。新建一个包:com.wingo.myfirstfsh.web.ro在包中新一个类:HelloWorld,作用flex的一个远程对象package com.wingo.myfirst.web.ro;public class HelloWorld public String sayHelloTo(String name)return Hello +name;在WEB-INF/flex/remotiong-config.xml中注册这个远程对象 com.wingo.myfirstfsh.web.ro.HelloWorld 编辑FLEX应用程序在src/ MyFirstFSH.mxml 中添加以下代码:启动tomcat 打开http:/localhost:8080/MyFirstFSH/pages/MyFirstFSH.html到了这一步,flex+bleazeds已经完成4.加上spring1.右键Myeclipse-Add spring2.添加包: mon3.添加SpringFactory.java(网上的)package mon;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; 4.在WEB-INF/flex中的services-config.xml中注册SpringFactory工厂5.在WEB-INF/web.xml中加入对spring的支持 contextConfigLocation /WEB-INF/applicationContext.xml SpringContextServlet org.springframework.web.context.ContextLoaderServlet 1 SpringLog4jConfigServlet org.springframework.web.util.Log4jConfigServlet web org.springframework.web.servlet.DispatcherServlet 5.添加hibernate1.添加数据源2.加进hibernate右键MyFirstFSH-MyEclipes-Add Hibernate点击:Finish3.添加包:结构如下4.删掉jar: 5.利用myeclipse自动生成User.java,User.hbm.xml,UserDAO打开:6.把UserDAO放到com.wingo.myfirstfsh.dao.impl下7.修改applicationContext.xml中对8.添加类代码如下:package com.wingo.myfirstfsh.service.impl;import com.wingo.myfirstfsh.dao.impl.UserDAO;import com.wingo.myfirstfsh.vo.User;public class IUserServiceImpl private UserDAO userDAO;/*通过ID搜索返回一个User对象 * param id 需要查找的用户ID * retur

温馨提示

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

评论

0/150

提交评论