Different Types of Spring Containers

There are two distinct types of spring containers as mentioned below:

1. BeanFactory Container:

  • This is the simplest container providing basic support for Dependency Injection and defined by the org.springframework.beans.factory.BeanFactory interface. Related interfaces, such as BeanFactoryAware, InitializingBean, DisposableBean, can provide callbacks which can be configured for the different phases of the Spring Bean’s life cycle.
  • BeanFactory, by default lazy loads the beans, it creates the bean only when the getBean() method is called.

2. ApplicationContext Container:

  • This container adds more enterprise-specific functionalities such as ability to resolve textual messages from a properties file and ability to publish application events to the interested event listeners. This container is defined by org.springframework.context.ApplicationContext interface.
  • ApplicationContext loads all Spring Beans upon start-up unlike BeanFactory.

ApplicationContext container includes all functionality of the BeanFactory container, so it is generally recommended over the BeanFactory. BeanFactory can be used for light weight applications like mobile devices or applet based applications where data volume and speed is significant.