Before you start
This tutorial will help you learn the basics of the Spring framework for application development, using Swing, and dependency injection, also known as Inversion of Control (IOC). After a brief overview of Spring and dependency injection, the bulk of the tutorial is hands-on, walking you step-by-step through creating a fully functional Swing application -- a to-do list program -- using Spring. The walk-through includes three options for a build environment, with detailed setup instructions for each one. You'll learn the basic use and benefits of the Spring framework in the process. Explanations of other relevant concepts are included along the way. You'll also take a few side trips to learn some good programming practices in the context of the tutorial code.
The last section is a brief and high-level review of the Spring Rich Client (RCP) framework, a subproject of the Spring framework that's working to provide a platform for developing rich-client Swing applications under Spring. The tutorial does not include step-by-step instructions for using the Spring RCP but is a starting point for obtaining the source code and exploring the project on your own.
The tutorial shows each new piece of code that you need to type. The complete source code is also available (see Download). The downloadable source code was created by following along and pasting code directly from the tutorial, so it should be bug-free and identical to what you create as you follow along. Because you'll write the GUI application in the Java programming language, it will run on any platform that Java code runs on.
This tutorial is not intended to be a comprehensive overview of the Spring framework or Swing. It does not cover use of Spring to create Web applications or access databases, or more-advanced topics such as Spring's support for aspect-oriented programming (AOP). Explore the tutorial's Resources for books, articles, tutorials, and online references that cover Spring and Swing in greater breadth and detail.
The audience for this tutorial is Java developers. It is intended to be accessible to multiple experience levels, and even if you are familiar with one topic you might still learn something about another. Some sections discuss related design patterns and development approaches. Feel free to skim past these if you are uninterested or already familiar with them. The following knowledge and skill levels will be helpful:
- Familiarity with the basics of the Java programming language, conventions for Java bean components, and experience with basic application design and development in the Java language.
- Basic knowledge of some build environment -- either Eclipse, Apache Ant, or Apache Maven (see Resources). But even if you are unfamiliar with these environments, you can follow the tutorial's fairly detailed instructions for using them. If you have problems with one, you can try one or both of the other two.
- Basic knowledge of XML syntax -- elements, attributes, and how to maintain a well-formed XML document (see Resources).
- Some basic familiarity with the Swing API, although the tutorial attempts to avoid the use of complex Swing code.
You need a computer with a JDK installed (JDK 1.5 is required to run the Rich Client Project demo in the final section) and an Internet connection for downloading the required tools and libraries.
One of the following is required, or you can use your own build environment or IDE:
- Apache Ant Version 1.6.1 or higher, available at http://ant.apache.org
- Apache Maven Version 1.0.2 or higher, available at http://maven.apache.org
- Eclipse version 3.0, 3.1, or higher, available at http://www.eclipse.org
In order to minimize the amount of up-front downloading work required to start the tutorial, both the Ant and Maven build scripts in the tutorial's source code provide support for automatically downloading the required dependency JARs (including Spring itself) from public repositories. This feature is built into Maven, and it is provided in the Ant script by the
get-dependencies target. To use these features with Eclipse, you must have Ant or Maven installed. You'll find more details in Environment setup.
You can obtain the correct required JAR versions manually if you prefer. Just refer to the
get-dependencies target in the Ant build.xml file (see Listing 1) to find out which JARs and versions are required, as well as the URLs to download them from.