,设置好环境变量。
Tomcat 6.0。 去官方下载MyEclipse 8.6。下载完毕,我先问候它妈一下--那么鬼难用! 在弹出的对话框的左侧栏,点General-->点Capabilities,然后把Classic Update前的框选上;其次是对于Flash Builder的网页模版js报错,解决方法是:在window--preferences--MyEclipse--Validation然后把JavaScript Validator这一项的Manual 和 Build的勾去掉。
设置一下Tomcat。
去官方网站下载Flash Builder 4.0插件版以及BlazeDS。安装前者以及解压后者。
下载MySQL以及GUI(本人比较懒)和jdbc的jar包。
Spring和Hibernate均使用MyEclipse内置即可。
为了可以调试,还必须下载调试版的Flash player.
现在开始我们的整合之旅。
我们将会写一个登录验证的例子。我们遵循从底层到上层的开发模式,由数据库开始。打开MySQL的GUI工具,创建一个叫做MyFlexDB的数据库。再创建一个叫做"User"的表,表的字段包含了id,username,password三个字段,其中id为自增并且为表主键。脚本如下:
CREATE TABLE `myflexdb`.`User` (
`id` INTEGER NOT NULL DEFAULT NULL AUTO_INCREMENT,
`username` VARCHAR(45),
`password` VARCHAR(45),
PRIMARY KEY (`id`)
)
ENGINE = InnoDB;
接着,我们创建一个Flex工程,名字叫做MyFlex。截屏如下:
输出配置信息,上下文根目录和内容文件夹如下:
令人很不爽的是context竟然不可以修改,真的不爽,搞到得硬编码指定endpoint值。点击next,看到 最后点击finish.
在服务端编写一个测试类Test,在客户端进行调用,配置remoting-config.xml(位于WEB-INF文件夹下面的Flex文件夹)。
Test类如下:
/**
* @author 黄记新
*
*/
public class Test {
public String testStr() {
return "hello,黄记新";
}
}
配置文件修改成为:
[/b][b]Test
默认使用my-amf通道即可。
前端主程序文件如下:
flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
用MyEclipse部署一下,启动服务器。
允许之后我们可以看到这样的画面:
点击按钮可以看到界面报错了,如下图: 原因是上下文错误。我们必须显式地指出endpoint的值。修改一下主文件,在远程类里面加上: endpoint='http://127.0.0.1:8080/MyFlex/messagebroker/amf'
再次运行可以看到:
接下来测试一下调试环境,使用调试的方式运行程序。
就是喜欢MyEclipse这种简单的调试环境。调试也成功了。
到此我们开始进入第二阶段的整合。
首先为工程加入Spring的jar包。如图所示,一般也别管什么东西了就一股脑加上吧。 点击next可以看到 此处主要是让用户是否对工程加入AOP支持和新建上下文配置文件的目录。
打开Hibernate的视图,新建数据库链接。
新建此链接等下我们在加入Hibernate支持的时候会使用到。
此处我们使用Spring来管理Hibernate链接。
此时Spring的上下文配置文件如下:
org.hibernate.dialect.MySQLDialect
新建三个包:com.myflex.model,com.myflex.service,com.myflex.dao
接下来我们做数据库映射,从数据库生成VO,dao。打开Hibernate视图。映射生成结果如图: 将dao文件拖拽到另外一个包中。
系统自动更新配置文件和引用位置。
我们做一下测试,顺便加几条数据到数据库当中。修改前面的Test类如下:
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
import com.myflex.dao.UserDAO;
import com.myflex.model.User;
/**
*
*/
/**
* @author 黄记新
*
*/
public class Test {
public String testStr() {
return "hello,黄记新";
}
public static void main(String[] args) {
User user=new User();
user.setUsername("黄记新");
user.setPassword("123456");
//使用上下文获得dao对象;
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext .xml");
UserDAO userDao=(UserDAO)context.getBean("UserDAO");
userDao.save(user);
//查找输出数据库对象
List list=userDao.findAll();
for (User user2 : list) {
System.out.println(user2.getId()+" "+user2.getUsername()+" "+user2.getPassword());
}
}
}
运行之后可以看到:
log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlA pplicationContext).
log4j:WARN Please initialize the log4j system properly.
1 黄记新 123456
2 韩冰 123456
接下来我们进入第三阶段,配置web.xml.主要是配置日志文件,Spring启动侦听器等。配置完毕后它的文件内容如下:
[/b][b]MyFlex
[/b][b]flex.class.path [/b][b]/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars [/b][b]contextConfigLocation [/b][b]/WEB-INF/classes/applicationContext.xml [/b][b]log4jConfigLocation [/b][b]/WEB-INF/log4j.properties [/b][b]webAppRootKey [/b][b]webApp.root Flex Session attribute and binding listener support --> [/b][b]flex.messaging.HttpFlexSession [/b][b]org.springframework.web.context.ContextLoaderListe ner [/b][b]org.springframework.web.util.Log4jConfigListener [/b][b]MessageBrokerServlet [/b][b]flex.messaging.MessageBrokerServlet [/b][b]services.configuration.file [/b][b]/WEB-INF/flex/services-config.xml [/b][b]flex.write.path [/b][b]/WEB-INF/flex [/b][b]1 [/b][b]MessageBrokerServlet [/b][b]/messagebroker/* [/b][b]index.html [/b][b]index.htm [/b][b]index.jsp [/b][b]default.html [/b][b]default.htm [/b][b]default.jsp [/b][b]/MyFlex.html [/b][b]BASIC [/b][b]Flex Messaging WorkManager [/b][b]wm/MessagingWorkManager com.ibm.websphere.asynchbeans.WorkManager Container [/b][b]Shareable 接下来我们增加一个工程类以及修改配置文件:
在服务端增加一个工程类,代码如下:
package com.myflex.factory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplica tionContextUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefini tionException;
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).
*
*
*
*
*
* 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:
*
*
* contextConfigLocation
* /WEB-INF/applicationContext.xml
*
*
*
* org.springframework.web.context.ContextLo aderListener
*
*
* Then you put your spring bean configuration in WEB-INF/applicationContext.xml (as per the
* line above). For example:
*
*
*
*
*
*
*
*
* Now you are ready to define a destination in flex that maps to this existing service.
* To do this you'd add this to your WEB-INF/flex/remoting-config.xml:
*
*
*
* spring
* weatherBean
*
*
*
* @authorJeffVroom
*/
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 FactoryInstance's 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; } } } } 在services-config.xml文件当中增加如下标签:
在remoting-config.xml文件当中增加:
[/b][b]springFactory
[/b][b]UserDAO
修改主文件:
flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
pageTitle="MyFlex">
最后阶段了,就是为DAO加入事务能力。
[/b][b]
[/b][b]PROPAGATION_REQUIRED
发表评论
-
解决Delphi截取字符串时遇到半个汉字
2012-07-06 09:52 2061演示程序中主要是用了 IsDBCSLeadByte 这个 ... -
js 学习笔记!
2012-07-06 09:46 6011.在ie 6 中 "//" 注释会 ... -
黑莓开发第三篇:常用UI组件
2012-07-03 13:44 825最低层次的UI 组件 可以处理自身的显示 用于显示各种 ... -
虚拟机随谈:解释器,树遍历解释器,基于栈与基于寄存器,大杂烩
2012-07-02 12:53 804虚拟机随谈:解释器,树遍历解释器,基于栈与基于寄存器, ... -
关于flexigrid一点用法
2012-07-02 12:52 580闲来无事在网上找了一个jquery的grid插件 flex ... -
如何使用registerClassAlias来解决module中使用RemoteObject---第一次访问正常、第二次出错
2012-07-02 12:52 584问题:今天我在Flex的module中使用RemoteOb ... -
超级面板皮肤及其使用
2012-07-02 12:52 669画出类似于遨游那样的最大化,最小化,关闭,还原按钮的皮肤。 ... -
flex 弹出的titleWindow 隐藏标题栏
2012-07-02 12:52 1771showTopPanelTitle.titleDispla ... -
Flex中调用FileReference.download()方法的限制【已解决】
2012-07-01 10:19 1967[2011-04-21 02:11:24] 问题解决。原因 ... -
Flex自定义鼠标右键
2012-07-01 10:19 792这里写了一个简单的自定义鼠标右键,代码不难,请看注释 ... -
Flex右键菜单扫盲
2012-07-01 10:18 935怎么添加右键?在 Flex 中,只有应用程序中的顶层组件才 ... -
走在网页游戏开发的路上(一)
2012-06-30 16:45 712走在网页游戏开发的路 ... -
2011-10-18
2012-06-30 16:45 6572011-10-18 2011年10月18日 ... -
文启领航教育:“内幕大公开”
2012-06-30 16:45 3文启领航教育:“内幕大 ... -
2011-11-24
2012-06-30 16:45 6932011-11-24 2011年11月24日 大型多人在 ... -
FLEX和Actionscript开发FLASH游戏 10-4
2012-06-30 16:45 587FLEX和Actionscript开发FLASH游戏 10-4 ...
相关推荐
。。。
。。。
Flex4.5 + Tomcat6.0 + MyEclipse 9.0+ Java+Blazeds环境配置和使用
MyEclipse 8.6安装Flash Builder 4.0插件方法
MyEclipse8.6+SpringMVC3.0+Hibernate3.3环境搭建,文档描述的很详细每个步骤都有文字和图片说明。文档还包括源代码和配置文件信息,特别适合初学者,本人自己写的。
用Eclipse3.1 + Myeclipse4.0 + Tomcat5.0 + j2sdk1.5 搭建J2EE开发环境
MyEclipse8.6+Struts2.1+Spring3.0+Hibernate3.3环境搭建,文档描述的很详细每个步骤都有文字和图片说明。
JDK+MyEclipse+Tomcat的配置
Android 4.0 +MyEclipse 9 整合开发环境搭建
Ubuntu下配置java环境(JDK1.6+eclipse+myeclipse+tomcat)
jsp环境搭建Eclipse3.2+MyEclipse5.5+Tomcat5.5,以及环境变量设置
搭建Eclipse3.2.2+MyEclipse5.5+Tomcat+Weblogic
Myeclipse8.5下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3
jsp环境搭建Eclipse3.2+MyEclipse5.5+Tomcat5.5.pdf
本教程介绍了"jdk1.6+MyEclipse6.5+Tomcat 6.0" 的开发环境的搭建设和配置,针对关键的每一步都进行了说明,另附截图,对新人来说比较容易理解和上手. 让新人少走弯路,对老鸟和大虾来说,就不用看了.
图解]jdk1.6_+_MyEclipse_7.0_+_tomcat-5.5_配置JSP环境
JDK1.6 + Tomcat6.0 + MyEclipse7.5 + Oracle XE(10g)
struts2+spring2+hibernate3集成示例 (开发环境:myeclipse5.5+tomcat6+jdk1.6) 描述:一个集成的登录小例子,供大家参考...