An IOC container is responsible for maintaining the lifecycle(managing, configuring etc) of the beans. The BeanFactory and ApplicationContext are two types of IOC containers provided by Spring. Let’s take a look:
It is basic IOC container hence lightweight.
It can only be configured using xml.
It does not support internationalization(i18n).
It does not support annotations.
There is only one class implementing BeanFactory i.e. XMLBeanFactory
It does lazy initialization of the beans. It only creates the beans when getBean() method is called.
How is it used
BeanFactory beanfactory = new XMLBeanFactory(new FileSystemResource("project-config.xml"));
It is an advanced inversion of control container. It is built on top of BeanFactory hence has all the features of BeanFactory as well.
It can be configured by XML as well as Annotations.
It supports internationalization(i18n).
It supports annotations.
Classes implementing ApplicationContext are ClassPathXMLApplicationContext, FileSystemXMLApplicationContext, XMLWebApplicationContext and AnnotationConfigWebApplicationContext.
It does eager initialization of the bean. It initializes the beans at the time of server startup.
It does automatic registration of Bean postprocessors.
It does automatic registration of BeanFactoryPostProcessor.
How is it used
ApplicationContext context = new ClassPathXmlApplicationContext("project-config.xml");
ApplicationContext context = new FileSystemXMLApplicationContext("C:/Users/prgrmmng/ HelloSpring/src/Beans.xml");
ApplicationContext context = new new XmlWebApplicationContext().setConfigLocation(location);
ApplicationContext context = new AnnotationConfigWebApplicationContext();