Junior — Middle
What are the different levels of scope for beans in the Spring Framework?
sobes.tech AI
Answer from AI
In the Spring Framework, the following main scope levels for beans exist:
- singleton (default) — one instance of the bean for the entire Spring container.
- prototype — a new bean instance is created each time it is requested.
- request — the bean lives for the duration of a single HTTP request (for web applications).
- session — the bean is tied to a user session.
- application — the bean exists within the scope of the ServletContext.
- websocket — the bean lives for the duration of a WebSocket session.
The choice of scope depends on how long the bean should exist and how it is used in the application.