9d (edited) • Backend
🫘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
3
2 comments
Ian Dancan
3
🫘Spring Bean Lifecycle
Amigoscode
skool.com/amigoscode
A free learning community led by Nelson Djalo. Master Programming & AI, get updates, and grow in a fast-moving industry.
Powered by