Before you start
For almost a decade, the "proper" way to build a robust and maintainable server-side Java application has been the exclusive domain of the Java 2 Enterprise Edition (J2EE) platform. J2EE applications are built using Enterprise JavaBeans (EJB) technology and run on servers that facilitate deployment and provide rich container services (such as the management of database connections and pooling). These servers also add value by providing deploy-time declarative control of important features such as security and transactions. Although versatile, the J2EE development process involves many tedious and repetitive tasks and the creation and maintenance of large numbers of source code files.
Many lightweight Java frameworks claim to simplify server application development, but none matches the Spring framework in maturity and popularity (see Resources). Now in version 2, Spring was designed from day one to simplify the server application building process. Instead of approaching development from an all-in-one container perspective, Spring aims to provide just enough support for an application's requirements without the burden of a full-fledged container environment. Spring eliminates code bloat: you can code and test business objects completely outside of any container, letting your business-object code remain simple, testable, maintainable, and reusable.
With the arrival of Java EE 5 and EJB 3.0, the J2EE community is poised to meet the Spring developer community. EJB 3.0 supports the notion of lightweight POJOs (Plain Old Java Objects) as EJB components and introduces the Java Persistence API (JPA), a persistence mechanism that can run externally to the container. This persistence mechanism automates the movement of information between business objects and external relational databases. Version 2 of the Spring framework has continued its evolution and also leverages JPA as a persistence mechanism.
In this tutorial, you will work with Spring 2 and JPA persistence. You'll create a server application using the Spring 2 framework, complete with access to a DB2 Express-C database. The Eclipse IDE facilitates the development of the Java application and enhances your exploration of the Spring 2 framework.
This tutorial aims to guide you through the use and application of the Spring 2 framework in the shortest possible time using a pure and simple learn-by-coding approach. You will build a Web application from scratch, step-by-step, assisted by the Spring 2 framework.
This tutorial does not attempt to cover all of Spring 2's features and options. Instead, it focuses narrowly on one proven approach to server application development using Spring. You are encouraged to consult other Spring 2 resources for more advanced applications and techniques related to the framework (see Resources).
You will proceed through a complete "from concept to application" cycle, including:
- Performing domain analysis
- Coding business objects and services
- Unit testing business objects
- Adding data access code painlessly to business objects using Spring JPA
- Implementing your services using Spring DAO (data access object)
- Coding integration tests for your services against DB2® Express-C
- Creating controllers for a Spring Model-View-Controller (MVC) based user interface
- Designing views for the user interface
- Creating a deployable WAR file of your application
- Configuring and deploying your application on the Apache Tomcat server
By the end of the tutorial, you'll understand how the Spring 2 framework works and how it can help you create highly componentized and maintainable Web applications. You'll gain working experience in building such an application and can apply many of the techniques you learn here to your daily development tasks.
You should be familiar with basic object-oriented design concepts and Java development using Java SE 5, including generics. Relational database concepts should be familiar to you, and you should have basic knowledge of how to set up a new database in DB2 Express-C.
Familiarity with testing terminology, including unit testing and integration testing, is assumed. Working experience with test frameworks such as JUnit is desirable, but not required.
You should have working experience with Eclipse and be able to create new Java projects, compile Java code, and debug projects within Eclipse.
The required hardware configuration for trying out the tools and example in this tutorial is a system with at least 512MB of memory (1GB recommended).
You need the following software installed:
- Sun's JDK 5.0_Update 7 or later or a version of the IBM® Developer Kit for the Java 5 platform.
- Spring framework 2.0. The code in this tutorial has been tested with Spring 2.0 RC 2. Select the "with-dependencies" version of the distribution. This will save you many additional downloads from different sites because it contains many of the required open source project binaries.
- A version of the Tomcat 5.5 server. Choose the ZIP file download for the server and unarchive it into a directory of your choice. This tutorial's code has been tested against Tomcat 5.5.17.
- DB2 Express-C (version 8.2.4 or later).
- Eclipse 3.2 or later, including the Web Tools Platform (WTP) 1.5 or later.
- The JPA reference implementation. Follow the full installation instructions in Writing DAO integration tests against an RDBMS in this tutorial.


