The Spring container is at the core of the Spring Framework. The container will create the objects, wire them together, configure them, and manage their complete life cycle from creation till destruction. The Spring container uses DI to manage the components that make up an application. These objects are called Spring Beans.
The container gets its instructions on what objects to instantiate, configure, and assemble by reading the configuration metadata provided.
The configuration metadata can be represented either by XML, Java annotations, or Java code. The following diagram represents a high-level view of how Spring works.

The Spring IoC container makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application.
The main tasks performed by IoC container are:
- Instantiate the application class
- Configure the object
- Assemble the dependencies between the objects
There are two types of IoC containers. They are:
- BeanFactory
- ApplicationContext
Using BeanFactory
The XmlBeanFactory is the implementation class for the
0 1 2 3 |
Resource resource=new ClassPathResource("applicationContext.xml"); BeanFactory factory=new XmlBeanFactory(resource); |
The constructor of XmlBeanFactory class receives the Resource object so we need to pass the resource object to create the object of
Using ApplicationContext
The ClassPathXmlApplicationContext class is the implementation class of
0 1 2 |
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); |
The constructor of ClassPathXmlApplicationContext class receives string, so we can pass the name of the xml file to create the instance of
Difference between BeanFactory and the ApplicationContext
The org.springframework.beans.factory.BeanFactory and the
It adds some extra functionality than