Chapter 2. The Bean Factory and Application Context

At the heart of Spring is its lightweight Inversion of Control (IoC) container functionality. One or more instances of a container are used to configure and wire together application and framework objects, and manage their lifecycles. The key principles of IoC ensure that the great majority of these objects do not have to have dependencies on the container itself, and can generally deal with related objects purely in terms of (Java) interfaces or abstract superclasses, without having to worry about how those other objects are implemented, or how to locate them. The IoC container is the basis for many of the features that will be introduced in the chapters that follow.

In this chapter, you will learn about the configuration and usage of Spring's bean factories and application contexts, as the embodiment of Spring's IoC container functionality. You will learn about the BeanFactory and ApplicationContext interfaces, along with related interfaces and classes, used when the container needs to be created or accessed in a programmatic fashion. This chapter will focus on the BeanFactory and ApplicationContext variants configured in a declarative fashion via XML. These generally have the most built-in functionality in terms of configuration and usage, and are the ones used by Spring users in the vast majority of cases. Note however that Spring decouples container configuration and usage. The next chapter will show how you may also access ...

Get Professional Java™ Development with the Spring Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.