`
wangyihust
  • 浏览: 442321 次
文章分类
社区版块
存档分类
最新评论
阅读更多

One of the hardest parts about J2EE development is getting started. There is an immense amount of open source tools for web app development. Making a decision on which technologies to use can be tough -- actually beginning to use them can be even more difficult. Once you've decided to use Struts and Hibernate, how do you go about implementing them? If you look on the Hibernate site or the Struts site, you'll probably have a hard time finding any information on integrating the two. What if you want to throw Spring into the mix? As a developer, the best way for me to learn is by viewing sample apps and tutorials that explain how to extend those applications. In order for me to learn (and remember) how to integrate open source technologies such as Hibernate, Spring, Struts, and Ant/XDoclet, I created AppFuse. The beauty of AppFuse is you can actually get started with Hibernate, Spring, and Struts without even knowing much about them. Using test-driven development, AppFuse and its tutorials will show you how to develop a J2EE web application quickly and efficiently.

The Birth of AppFuse

In early 2002, I managed to land a contract where I was the lone developer. I was responsible for everything, from gathering requirements to database creation to DHTML on the web front end. While I'd done a lot of front-end work (Struts, HTML, etc.) over the years, the business layer and persistence layer were mostly new to me. So I searched and searched for J2EE patterns to do things the "right way" for my new client. I ended up implementing Business Delegates, DAOs, and ServiceLocators -- many of them modeled after J2EE Blueprints. Towards the end of that contract, I was contracted to help write a book on JSP 2.0. The publisher was Wrox Press and the book was Professional JSP 2.0. I volunteered to write two chapters -- one on Struts and one on web security. Note: in March 2003, Wrox went out of business and this book eventually became Pro JSP, Third Edition, published by Apress.

When you write a technical book, it's helpful to use a sample app to demonstrate concepts. I was tired of reading books that had a throwaway sample app, so I wanted to develop something meaningful; something I could use after I was done writing. My initial thoughts were to write an application that would help you get started with Struts, and would use XDoclet to do a lot of the heavy lifting. It also had to have a lot of security features so I could use it for my chapter on web application security. I came up with the name struts-xdoclet and began developing my application.

After a couple of weeks, I decided that "struts-xdoclet" was too hard to say and renamed the project AppFuse. I developed the sample app for my Struts chapter using AppFuse and released it as Struts Resume. After publishing Struts Resume, I needed to extract the resume-specific stuff out of it to revert back to the generic "jumpstart" application I wanted AppFuse to be. It took me almost three months, but I finally released the first official version of AppFuse in April 2003.

Since its initial release, AppFuse has gone through many changes and improvements. Most of the technology decisions were made from experience. It was a pain to keep my ValueObjects (VOs) and ActionForms in sync, so ActionsForms are generated using XDoclet. I found it tedious to write JDBC and more tedious to update SQL and VOs when adding new table columns. To solve this, I chose to use Hibernate for persistence and use Ant/XDoclet to dynamically create my database tables. Rather than lose my tables' data each time, I integrated DBUnit, which also came in handy when running unit tests. I decided to use Tomcat/MySQL as the default server/database setup because I was most familiar with them. I integrated a plethora of unit/integration tests so I could make sweeping changes and verify that everything still worked (including the JSPs) by running ant test-all.

In March of 2004, I moved the AppFuse project from the Struts project on SourceForge to java.net. I had a couple of reasons for doing this. First of all, it was a sub-project on SourceForge, and its user base was growing quickly. It needed dedicated mailing lists and forums. Secondly, java.net seemed to do a better job of marketing projects and I'd heard their CVS system was much more stable. My experience at java.net has been quite nice: it's a very stable system, and the administrators are very supportive of the project and have even helped with marketing it.

What is 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 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).

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.

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.

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.

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

    AppFuse 是一个开源项目,旨在简化Java Web应用程序的开发过程。它提供了一个基础框架,集成了许多流行的开源库,如Spring、Hibernate、Struts或Spring Boot等,帮助开发者快速搭建应用骨架。AppFuse 可以根据选定的...

    appfuse学习笔记(一)安装部署

    **AppFuse 学习笔记(一):安装与部署** AppFuse 是一个开源项目,它提供了一种快速构建企业级 Web 应用程序的方式。它使用了多种流行的技术栈,如 Spring Boot、Hibernate、Thymeleaf 和 Maven,使得开发者可以更...

    AppFuse入门文档(AppFuse与SpringMVC+mybatis整合)

    ### AppFuse与SpringMVC+MyBatis整合详解 #### 一、概述 AppFuse是一个开源的应用程序骨架,主要用于快速构建基于Java的企业级应用。它提供了丰富的模板和配置,能够帮助开发者快速搭建起一个完整的应用架构。本...

    APPFUSE工具研究.doc

    AppFuse 是一个基于Java平台的开源项目,旨在加速和简化Web应用程序的开发。它通过集成各种流行框架,如Struts、Spring、Hibernate等,提供了一个项目骨架,使得开发者能够快速搭建新项目的结构。AppFuse分为1.x和...

    可直接使用的appfuse项目

    AppFuse是一个集成了众多当前最流行开源框架与工具(包括Hibernate、ibatis、Struts、Spring、DBUnit、Maven、Log4J、Struts Menu、Xdoclet、SiteMesh、OSCache、JUnit、JSTL等(现在还有lucene的,无敌了))于一身的...

    建立项目原型骨架的步骤(最新版本appfuse)appfuse2.1.0-M2

    AppFuse 是一个开源项目,它提供了快速开发Java Web应用程序的基础框架。这个框架集成了Spring、Hibernate和Struts等主流技术,使得开发者能够迅速构建出符合MVC架构的应用。在最新的版本2.1.0-M2中,AppFuse 提供了...

    AppFuse2.1所需包

    AppFuse 是一个开源项目,旨在简化Java Web应用程序的开发。它提供了一个基础架构,开发者可以在此基础上快速构建安全、可扩展的应用程序。AppFuse 2.1 版本是该项目的一个较早版本,但仍然包含了现代Web开发的核心...

    基于AppFuse框架的B2C电子商务系统研究与实现

    AppFuse是一个开源项目,旨在简化Java Web应用的开发。它提供了一个基础结构,开发者可以在此基础上快速构建安全、模块化的应用程序。本项目是关于利用AppFuse框架构建B2C(Business-to-Consumer)电子商务系统的...

    Appfuse开发教程

    **Appfuse开发教程** Appfuse 是一个开源项目,它提供了一种快速开发Web应用程序的方式,尤其在使用Java技术栈时。本教程将深入探讨如何利用Appfuse创建数据访问对象(DAO)和简单Java对象(POJO),并进行数据库...

    AppFuse项目研究

    AppFuse 是一个由 Matt Raible 创建的开源项目,旨在为初学者提供一个快速入门的 J2EE 框架模板。它集成了多种流行的技术,包括 Spring、Hibernate、iBatis、Struts、Xdoclet 和 JUnit,同时也支持 Taperstry 和 JSF...

    appfuse1.4-architecture

    06年时的appfuse,学习SSH架构的经典入门框架。相对比较老的资料,可以欣赏一下当时的架构,向牛人致敬

    Appfuse1.9至2.0.2

    主要是自己从网络上搜集的一些关于appfuse1.8.2-2.0.2的一些相关资料,间或有点自己试验的记录,还有点maven和quartz的东东,之前我主要是用1.8.2构建项目,感觉还不错,希望对想学习appfuse的人有些帮助.

    MAVEN 搭建APPFUSE

    【MAVEN 搭建APPFUSE】是一个关于使用Maven构建基于AppFuse的应用程序的教程。AppFuse是一个开源项目,旨在简化Web应用程序的开发,它提供了一个基础框架,可以帮助开发者快速启动新项目,整合了Spring、Hibernate、...

    SSH学习及开发框架-appfuse

    appfuse 有struts2+hibernate+spring的整合 springmvc+hibernate+spring的整合 多模块,但模块都有 学习开发参考使用非常方便 可以到官方下载最新版的,我只是把自己下载的打包整理一下 注意哈,都是基于maven的...

    玩转appfuse--使用appfuse建设MVC网站

    **玩转AppFuse:使用AppFuse建设MVC网站** AppFuse是一个开源项目,它提供了一个快速启动MVC(Model-View-Controller)Web应用程序开发的框架。基于Java,AppFuse集成了Spring、Struts2、Hibernate等流行的技术,极...

    appfuse2学习日记

    ### AppFuse2 学习知识点总结 #### 一、AppFuse 概述 - **定义与价值**:AppFuse 是一款开源项目,旨在利用一系列开源工具帮助开发者高效地搭建 Web 应用程序的基础架构。通过使用 AppFuse,开发人员可以在构建新...

Global site tag (gtag.js) - Google Analytics