The Spring container (also known as IOC container) is at the core of the Spring framework.
In Spring, objects get stored and live in container. So it becomes significant to learn about the container as it will help us to manage the objects during its life-cycle.
The Spring Container is responsible to:
create the objects (bean)
wire the created objects together
configure the objects
manage the objects complete life cycle from creation till destruction.
Spring container uses Dependency Injection to manage all the components that forms an application.
Working of Spring container
The following diagram clearly explains the working of the Spring container from high level perspective.
Spring Container takes as input two things:
Java based POJO classes
Configuration Metadata which contains the complete information about What bean to create, its type, dependencies, etc.
The configuration metadata can be provided in three formats:
XML config file
Java config file
We can use any of the above format or all at the same time to provide the configuration metadata to Spring container. There is no restriction on which one to use.
Using any of the above will help you in acheive your task.
As we have already explained that in Spring objects do not have responsibility of finding or creating their dependency that need to complete their task. Rather the Spring container takes the responsibility of giving the reference to the objects with whom they need to collaborate with.
Spring container is able to perform the tasks of creating the object, configuring them, wiring them together by reading the details given in configuration metadata.
Types of Spring container
Spring containers are generally categorized as:
We will learn more about both of them in next chapters of this tutorial.