A Spring container is the backbone of the framework. A container is basically a pool of beans created in a memory space by the framework when the application starts up. An API provided by the framework exposes methods to query these beans from the container.
We’ll start the chapter by looking at the containers and different categories. We’ll also look at details about concepts such as AutoWiring.
Understanding containers is an important task when working with the Spring Framework as they are crucial moving pieces in a Spring’s jig-saw puzzle.
During the startup process, the beans are instantiated, the associations and relationships are created, all the relationships are satisfied, and dependencies are injected. All named beans are available for querying using an API. Some beans are lazily loaded while others are loaded during the initialization of the container. This means that unless the bean is requested by our application or some other bean (as a part of dependency), the framework will not instantiate the bean, except loading singletons.
Spring containers primarily fall into two categories: Bean Factories
and Application Contexts—supported by the
respectively. The names are sort of misnomers, as they do not give any clue as to what these
containers are and what they do.
BeanFactory is a simple
container supporting basic dependency injection, whereas
ApplicationContext is an extension of
BeanFactory, which ...