C H A P T E R 1
■ ■ ■
Introduction to Spring
In this chapter, you will be given a crash course refresher on Spring, the core container, as well as some
of the globally available facilities provided by the container, such as aspect-oriented programming (AOP) .
You will also become acquainted with the Spring XML configuration format as well as the annotation-
driven support. The core framework has changed in many ways, and coverage of the additional
configuration options is available in Chapter 2.
One of the most notable shifts in the core framework was the change from AOP support in the 1.x
release of Spring to the AOP support starting from version 2.0. The Spring framework overhauled its
AOP support, integrating with AspectJ_a separate project whose functionality can mostly be leveraged
entirely from the familiar Spring Inversion of Control (IoC) environment. Typically, you will deal very
little with AOP directly in the course of your Spring framework programming. You will interface with it
indirectly in some of the more core support (such as with transactions), but only as a client of the
This chapter will give you the knowledge you need to deal with the concepts introduced in the rest
of the topic."
1-1. Instantiating the Spring IoC Container
You have to instantiate the Spring IoC container for it to create bean instances by reading their
configurations. Then you can get the bean instances from the IoC container to use.
Spring provides two types of IoC container implementation. The basic one is called bean factory . The
more advanced one is called application context , which is a compatible extension to the bean factory.
Note that the bean configuration files for these two types of IoC containers are identical.
The application context provides more advanced features than the bean factory while keeping the
basic features compatible. So I strongly recommend using the application context for every application
unless the resources of this application are restricted, such as when running in an applet or a mobile
The interfaces for the bean factory and the application context are BeanFactory and
ApplicationContext , respectively. The interface ApplicationContext is a subinterface of
BeanFactory for maintaining compatibility.