设为首页 收藏本站
查看: 939|回复: 0

[经验分享] 整合Flash Builder4.0+MyEclipse 8.6+BlazeDS+Sping 3.0+Hibernate3.3+MySQL5.5+Tomcat+

[复制链接]

尚未签到

发表于 2017-2-11 06:33:24 | 显示全部楼层 |阅读模式
  ,设置好环境变量。
  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(本人比较懒)和jdbcjar包。
  SpringHibernate均使用MyEclipse内置即可。
  为了可以调试,还必须下载调试版的Flash player.
  现在开始我们的整合之旅。
  我们将会写一个登录验证的例子。我们遵循从底层到上层的开发模式,由数据库开始。打开MySQLGUI工具,创建一个叫做MyFlexDB的数据库。再创建一个叫做"User"的表,表的字段包含了idusernamepassword三个字段,其中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,黄记新";
  }
  }
  配置文件修改成为:
  
  
  
  
  
  
  
  
  
  
  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这种简单的调试环境。调试也成功了。
  到此我们开始进入第二阶段的整合。
  首先为工程加入Springjar包。如图所示,一般也别管什么东西了就一股脑加上吧。 点击next可以看到 此处主要是让用户是否对工程加入AOP支持和新建上下文配置文件的目录。
  打开Hibernate的视图,新建数据库链接。
  新建此链接等下我们在加入Hibernate支持的时候会使用到。
  此处我们使用Spring来管理Hibernate链接。
  此时Spring的上下文配置文件如下:
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  org.hibernate.dialect.MySQLDialect
  
  
  
  
  新建三个包:com.myflex.modelcom.myflex.service,com.myflex.dao
  接下来我们做数据库映射,从数据库生成VOdao。打开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启动侦听器等。配置完毕后它的文件内容如下:
  
  
  MyFlex
  flex.class.path/WEB-INF/flex/hotfixes,/WEB-INF/flex/jarscontextConfigLocation/WEB-INF/classes/applicationContext.xmllog4jConfigLocation/WEB-INF/log4j.propertieswebAppRootKeywebApp.rootFlexSession attribute and binding listener support --> flex.messaging.HttpFlexSessionorg.springframework.web.context.ContextLoaderListe nerorg.springframework.web.util.Log4jConfigListenerMessageBrokerServletflex.messaging.MessageBrokerServletservices.configuration.file/WEB-INF/flex/services-config.xmlflex.write.path/WEB-INF/flex1MessageBrokerServlet/messagebroker/*index.htmlindex.htmindex.jspdefault.htmldefault.htmdefault.jsp/MyFlex.htmlBASICFlexMessaging WorkManager wm/MessagingWorkManager com.ibm.websphere.asynchbeans.WorkManager Container 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 flexmessaging framework.To configure flexdata services  
  * to use this factory, add the following lines to your services-config.xml  
  * file (located in the WEB-INF/flexdirectory 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/libdirectory.To configure your appserver 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 flexthat maps to this existing service.  
  * To do this you'd add this to your WEB-INF/flex/remoting-config.xml:  
  *  
  *
  *
  *spring  
  *weatherBean  
  *
  *
  *  
  * @authorJeffVroom
  */
  public classSpringFactory implementsFlexFactory  
  {  privatestaticfinalString 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.*/ publicvoidinitialize(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.  */ publicFactoryInstance createFactoryInstance(String id, ConfigMap properties)  {  SpringFactoryInstance instance = newSpringFactoryInstance(this, id, properties);  instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));  returninstance;  } // 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.  */ publicObject lookup(FactoryInstance inst)  {  SpringFactoryInstance factoryInstance = (SpringFactoryInstance) inst;  returnfactoryInstance.lookup();  }  staticclassSpringFactoryInstance extendsFactoryInstance  {  SpringFactoryInstance(SpringFactory factory, String id, ConfigMap properties)  {  super(factory, id, properties);  }  publicString toString()  {  return"SpringFactory instance for id="+ getId() + " source="+ getSource() + " scope="+ getScope();  }  publicObject lookup()  {  ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(flex.messaging.FlexContext.getServletConfig().getServletContext());  String beanName = getSource();  try {  returnappContext.getBean(beanName);  }  catch(NoSuchBeanDefinitionException nexc)  {  ServiceException e = newServiceException();  String msg = "Spring service named '"+ beanName + "' does not exist.";  e.setMessage(msg);  e.setRootCause(nexc);  e.setDetails(msg);  e.setCode("Server.Processing");  throwe;  }  catch(BeansException bexc)  {  ServiceException e = newServiceException();  String msg = "Unable to create Spring service named '"+ beanName + "' ";  e.setMessage(msg);  e.setRootCause(bexc);  e.setDetails(msg);  e.setCode("Server.Processing");  throwe;  }  }  }  }  services-config.xml文件当中增加如下标签:
  
  
  
  remoting-config.xml文件当中增加:
  
  
  springFactory
  UserDAO
  
  
  修改主文件:
  
  flex/spark"  
  xmlns:mx="library://ns.adobe.com/flex/mx"  
  minWidth="955" minHeight="600"
  pageTitle="MyFlex">
  
  
  
  
  
  
  
  最后阶段了,就是为DAO加入事务能力。
     
  
  
  
  
  
  
  
  
  
  PROPAGATION_REQUIRED
  
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-340370-1-1.html 上篇帖子: web应用增加webservice后从tomcat移植到weblogic后各种类冲突,各种异常解决 下篇帖子: java.util.Timer做的定时器怎样在tomcat启动的时候就开始定时?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表