3          What is AppFuse?

AppFuse 是什么?

So after all that history, what is AppFuse? At its very core, AppFuse is a web application that you can package into a .war and deploy to a J2EE 1.3-compliant app server. It’s designed to help you create new web applications using a new target in its build.xml file. The new target allows you to specify a name for your project and a name for the database it will talk to. Once you’ve created a project, you can instantly create a MySQL database and deploy it to Tomcat using ant setup. Furthermore, you can verify that the basic functionality of your new application works by running ant test-all. At this point, you might sneer and say, “What’s the big deal? Anyone can create a .war file and deploy it to Tomcat.” I agree, but do you have a setup-tomcat target that will configure Tomcat with JNDI resources for connections pooling and mail services? Most of what AppFuse does is not rocket science. In reality, it’s nothing more than a directory structure, a build file, and a bunch of base classes — with a few features thrown in. However, it has vastly accelerated my ability to start projects and develop high-quality, well-tested web applications.

AppFuse究竟是什么?AppFuse是一个你可以打包位一个war文件并可以在兼容J2EE 1.3的应用服务器中运行的web应用程序。它被设计成能够利用build.xmlnew target帮助你建立新的的web应用程序。new target允许你指定你的项目名称和数据库名称。一旦你建立了一个项目后,你可以利用ant setup创建MySQL数据库并发布程序到Tomcat。而且你可以执行ant test-all测试新工程的基本功能。这时,你可能会嘲笑说,“这有什么的,任何人都可以创建一个.war文件并发布到tomcat”.我同意这点,但是你有setup-tomcat target可以用来配置Tomcat的连接池的JNDI资源和mail services?事实上,AppFuse并不是什么突破性的发明,它只是由一个目录结构,一个build文件,一堆基类等组成,然而,它能够让我能够快速构建可以高质量开发,易于测试的web应用程序。

AppFuse tries to make it as simple as possible to build, test, and deploy your application. It virtually eliminates setup and configuration, which are often the hard parts. Tools like Ant, JUnit, XDoclet, Hibernate, and Spring can be difficult to get started with. Furthermore, features like authentication, password hints, “remember me,” user registration, and user management are things that most web apps need. AppFuse ships with tutorials for developing DAOs, business delegates, Struts actions (or Spring controllers), integrating tiles and validation, and uses an Ant-based XDoclet task (written by Erik Hatcher) to generate master/detail JSPs from model objects. It uses slick open source tag libraries like Struts Menu (for navigation) and the Display Tag (for paging and sorting lists).

AppFuse试图尽可能简单的建造,测试,和发布你的程序。它实际上免去了安装和配置,这些往往是非常困难的部分。同时使用像Ant,JUnit,XDoclet,HibernatesSpring这样的工具是非常困难的。此外,还有一些像权限,密码提示,记住我”,用户注册和用户管理这些大多数web应用程序需要的部分往往是必须的。AppFuse还包括了开发DAOs, business delegates, Struts actions (or Spring controllers), 多层之间的通讯和验证,以及根据model objects 使用antXDoclet任务去生成一些JSP代码的指南。它还使用了很多优秀的开源标签库例如Struts Menu (用来导航) and the Display Tag (用来翻页和排序).

One of the best parts, in my opinion, is that it embraces the Java community’s ideas and suggestions. The directory structure and build file are largely based on Erik Hatcher and Steve Loughran’s excellent Java Development with Ant book. In this book, Erik built a sample application that inspired me to learn more about Ant and XDoclet — and use it in my Struts development.

在我看来,AppFuse最好的部分之一是集合了java社团的想法和建议。目录结构和build文件主要来自于Erik Hatcher Steve Loughran’的著作Java Development with Ant。在这本书里,Erik使用的一个示例程序给了我对于使用AntXDoclet的很多启示而且用在了我的Struts开发中。

When I first started learning and using Hibernate in AppFuse, I made many mistakes — and the community let me know. At first, I opened and closed its Session object for each DAO method. When Gavin told me this was a bad idea, I made modifications to use an OpenSessionInView pattern, with my own ServletFilter to do the work. I passed the session object into each method signature, for which the community repeatedly questioned my logic. My answer was, “I wanted to get it working more than anything — do you have a better idea?” The better idea turned out to be using the Session as a constructor argument, which worked pretty well.

当我第一次在AppFuse中开始学习和使用Hibernate时,我犯了很多错误,但是java社团帮助我纠正了错误。一开始我在每个DAO的方法中openedclosed他们的Session对象。当Gavin告诉我这是非常不好的方法,我修改为使用OpenSessionInView模式,让我的ServletFilter来做这件事情。我将session对象作为参数传递给每个方法,大家都很奇怪我的这样做的原因。我的回答是:我首先得让程序能够工作你们有更好的主意吗?”最后讨论出最好的主意是将Session做为构造函数的一个参数。

Then, late last year, I discovered the Spring framework and found the beautiful solution I’d been looking for. Using its ORM support, I was able to eliminate any Session handling in AppFuse; now Spring elegantly handles it all. AppFuse now uses Spring’s OpenSessionInViewFilter. All I needed to do was configure it in web.xml and it manages opening and closing the session for me. When I integrated Spring in AppFuse’s persistence layer, I deleted two or three classes and reduced my LOC count by around 75 percent. All of the Hibernate issues I’d had before disappeared! In addition, I was quickly able to add a DAO implementation using iBATIS, which I worked with on a project last year. On that project, I discovered that iBATIS was easy to use and worked very well for interacting with complex database schemas.

在去年的晚些时候,我看到了Spring framework并且发现这是我正在一直寻找的优秀解决方案。使用他的ORM,我能够消除所有的Session操作在AppFuse中。Spring已经优雅的处理了他们。AppFuse 现在使用了 Spring OpenSessionInViewFilter。我所需要做的只是在web.xml中配置一下它就可以为我管理session的打开和关闭。当我集成了springAppFuse的数据持久层,我删除了两到三个class并且减少了大概百分之七十五的LOC数量。所有以前我使用的Hibernate 耦合都消失了,在我去年的一个项目上,我可以很方便的加入iBatisDAO实现。在这个项目上,我发现iBATIS非常容易使用并且在复杂的数据库结构上使用的非常好。

AppFuse is not only a jumpstart kit for your web apps; it’s also a showcase for integrating technologies like Hibernate, Spring, and Struts. Tutorials exist for integrating these different open source components, but rarely do they give you an application you can walk away with and use to develop your next application. In a sense, AppFuse is a glue that binds open source projects together. When I found Spring, it was a perfect fit, since it was the glue to configure components and loosely couple the different layers of an application. Erik’s book might have been the match that lit AppFuse, but Spring is the gasoline that really got it roaring. Spring has vastly simplified how I develop with AppFuse and forced me to follow best practices in J2EE. In short, it’s the best tool I’ve ever used with J2EE. I realize Spring is not the be-all-end-all for J2EE applications — AppFuse worked fine before I integrated it. However, it helped answer all of my “How should I do …” questions — which was a nice relief.

AppFuse不仅仅是一个web apps的框架搭建工具,它也是整合各种像Hibernate, Spring,Struts技术的展示柜。现在的一些指南能够告诉你如何整合这些不同的开源工具,但是很少能够提供一个你直接拿来就能用开发你的下一个项目的东西。在某种意义上,AppFuse是将开源技术绑定到一起的融合剂。当我发现了spring,它是非常的适合,因为它可以配置组件并且使得程序中不同的layer松耦合。Erik的书可能是点亮AppFuse的火柴,但是Spring就像汽油一样使得马达轰鸣起来。spring使我开发AppFuse非常的统一化并强迫我按照best practices in J2EE来做。简而言之,它是我在J2EE中使用过最好的工具。我认为到Spring不仅是所有J2EE程序所必须的――AppFuse在我整合它以前也跑的很好。但是它帮助回答了我所有”…..该怎么做?的问题这真是雪中送炭。


1条评论

  1. 你真有空!

发表评论

评论也有版权!