Topic 1: Spring Core — IoC, DI, AOP, Bean Lifecycle

What You’ll Learn:


1. Inversion of Control (IoC) & Dependency Injection (DI)

Inversion of Control:

Instead of classes creating their dependencies, the container injects them.

Dependency Injection:

A design pattern where an object’s dependencies are provided externally.

Without DI:

class Service {
    Repo repo = new Repo(); // tight coupling
}

With DI (Spring style):

@Component
class Service {
    private final Repo repo;
    @Autowired
    Service(Repo repo) { this.repo = repo; }
}


2. Spring Bean Lifecycle

Phase Hook
Instantiation Constructor
Dependency Injection @Autowired
Initialization @PostConstruct, InitializingBean.afterPropertiesSet()
Destruction @PreDestroy, DisposableBean.destroy()

Example: