1.

What is the difference between BeanFactory and ApplicationContext?

Answer»

BeanFactory is an INTERFACE that is the core of Spring’s Dependency Injection container. It is responsible for managing the components (beans), their dependencies and lifecycle.

BeanFactory can be configured using either a configuration XML file or by programmatically which is the case with Spring Boot. It creates a unique identifier for each Bean in the application.

BeanFactory is also called basic IOC, whereas ApplicationContext is called Advanced IOC. Although BeanFactory and ApplicationContext both are used to GET the beans from IOC container and inject them as per the configuration.

Below are the significant differences in implementation:

  1. BeanFactory uses lazy initialization i.e. it creates a singleton bean only when it is requested; whereas ApplicationContext uses eager initialization as it creates all singleton beans at the time of initialization.
  2. ApplicationContext creates and manages resources objects on its own whereas in the case of BeanFactory we need to explicitly provide the RESOURCE details.
  3. ApplicationContext supports internationalization but BeanFactory does not.
  4. Annotation-based dependency Injection is not supported by BeanFactory whereas ApplicationContext supports ANNOTATIONS like @PreDestroy, @Autowired, etc.


Discussion

No Comment Found