Bean Scopes and Lifecycle Management
Learn how Spring creates, scopes, and destroys beans, and how to hook into their lifecycle with callbacks.
What Is a Bean Scope?
A scope defines how many instances of a bean Spring creates and how long they live. The default scope is singleton: one shared instance per container.
Singleton Scope
With singleton, every injection point receives the same object. This is ideal for stateless services and is the most common choice.
@Service
public class PricingService {
// one shared instance across the app
}All lessons in this course
- Understanding Spring IoC Container
- Dependency Injection in Practice
- Externalizing Application Properties
- Bean Scopes and Lifecycle Management