What is IoC Container in Spring

Spring Container is core of Spring framework. Spring Container is responsible for instantiating beans, configure  and assemble them together. It manage their compete life-cycle from creation to destruction. The Container gets its instruction on what object to instantiate, configure and assemble by reading configuration metadata. The configuration  metadata is represented by XML, Java annotation and Java code.

There are two types of IoC Container in Spring-

  1. BeanFactory
  2. ApplicationContext
1. BeanFactory : BeanFactory is simplest container. This is defined by org.springframework.bean.factory.BeanFactory interface. The most commonly used BeanFactory implementation is the XmlBeanFactory class. BeanFactory instantiate bean when getBean("") method is called.

2. ApplicationContext : ApplicationContext is more advanced container. This is defined by org.springframework.context.ApplicationContext interface.This interface extends org.springframework.bean.factory.BeanFactory. 

 It adds some more functionality than BeanFactory such as simple integration with AOP, message resource handling(for I18n), even propogation, application layer specific context(eg. WebXmlApplicationContext) for web application. So it is better to use ApplicationContext than BeanFactory.

ApplicationContext create and configure bean when configuration metadata is loaded(when container started). It does not wait for getBean to be called.

This most commonly used ApplicationContext implementation are :

  1. FileSystemXmlApplicationContext
  2. ClassPathXmlApplicationContext
  3. WebXmlApplicationContext

Comments

Popular posts from this blog

Data types and Literals in Java

How to define Auxiliary Constructor in case class in Scala

equals() method of Object class in Java