1. Understanding Spring’s IoC Container
The Inversion of Control (IoC) container is the foundation of the Spring framework. It manages the lifecycle and configuration of objects (beans) and their dependencies. The IoC container:
- Instantiates beans.
- Resolves and injects dependencies.
- Configures bean lifecycle callbacks.
Types of IoC Containers in Spring:
- BeanFactory: The basic IoC container for simple applications.
- ApplicationContext: An advanced container with support for AOP, internationalization, and event handling.
2. Types of Dependency Injection
Spring supports two main types of dependency injection:
- Constructor Injection
- Setter Injection
a. Constructor Injection
Dependencies are provided via the constructor at the time of object creation.