Senior
How many scopes are there in a Spring application?
sobes.tech AI
Answer from AI
In the Spring Framework, there are several types of scopes for beans that define the lifespan and visibility of instances:
- Singleton (default) — one bean instance per 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 lives for the duration of an HTTP session.
- Application — the bean lives within the ServletContext (web application).
- Websocket — the bean lives for the duration of a WebSocket session.
Thus, in a standard Spring application, 6 main scopes are available. In non-web applications, usually only singleton and prototype are used.