đ«Spring Bean Lifecycle
Every Spring Boot app youâve ever run quietly creates, wires, and destroys objects for you, in other terms, this is Inversion of Control (IoC), a concept weâll break down later. 1. Instantiation Spring creates the bean instance. 2. Dependency Injection Dependencies are injected (@Autowired, constructor injection, etc.). 3. Initialization (@PostConstruct) Custom setup logic runs after dependencies are ready. 4. Ready State Bean is fully initialized and used across the application. 5. Context Shutdown Application begins shutdown. 6. Cleanup (@PreDestroy) Cleanup logic runs (closing resources, connections). 7. Bean Destroyed Bean is removed and becomes eligible for garbage collection. Bean Scopes (Important) - Singleton (default): One instance per application - Prototype: New instance each time requested - Request / Session: Scoped to HTTP request or session