Senior
What scopes of beans do you know in Spring?
sobes.tech AI
Answer from AI
In Spring, the following main bean scopes exist:
- singleton (default) — one instance of the bean for the entire Spring context.
- prototype — a new bean instance is created each time it is requested.
- request — the bean lives within the scope of an HTTP request (for web applications).
- session — the bean lives within the scope of an HTTP session.
- application — the bean lives within the scope of the ServletContext.
- websocket — the bean lives within the scope of a WebSocket session.
Each scope defines the lifetime and visibility of the bean, allowing flexible management of state and resources in the application.