Understanding Spring Container in Spring Framework

In previous tutorial of spring framework we have seen what dependency injection is and the usage of dependency injection. We have also seen the dependency object will be created and injected by Spring Container. In this tutorial we will what spring container is and the role of it in spring framework.

Understanding Spring Container or IOC Container

Understanding Spring Container or IOC Container

Spring Container is similar to Servlet Container, so if we understand the role of servlet container we will understand the Container as well.

Servlet Container

Servlet container will read configuration details (web.xml), instantiate the servlet object, pass the property values and manages the servlet life cycle starting from instantiation to destruction.

Spring Container

Similarly in Spring, Container will read configuration file, creates the object(s) and dependency object(s), inject the dependencies and manages the bean/pojo life cycles.

Spring Container or IOC Container                          Spring Container or IOC Container in Spring

As mentioned in above figure Container will read xml file which contains configuration details about Pojo. Using Java Reflection, it will create dependency object along with all the required properties, also it will inject dependency object into our pojo classes.

In Spring, Container will read the configuration from xml file or through java annotation or by using Java Code. In our forthcoming tutorials we will see examples of each one.

Spring Container or IOC Container and its Types

Spring Container can also be specified as IOC container. IOC Container can be classified as two types

  • Core Container and
  • J2EE Container


We also have one more container in spring called Web Container.

Spring Core Container:

       org.springframework.beans.factory.BeanFactory (Interface) implementation was provided by org.springframework.beans.factory.xml.XmlBeanFactory class.

J2EE Container:

          org.springframework.context.ApplicationContext (Interface) extended by org.springframework.context.ConfigurableApplicationContext (Interface) and it’s has two important implementations i.e org.springframework.context.support.ClasspathXmlApplicationContext (class) and org.springframework.context.support.FileSystemXmlApplicationContext (class)

We also have other implementation like WebXmlApplicationContext and XmlWebApplicationContext which we will see in our future tutorials. We will also see in details about BeanFactory and ApplicationContext in the future details.

Please post your questions in the comment box, if you like this tutorial please share it with your friends.

Leave a comment

Your email address will not be published. Required fields are marked *