Junior — Middle
What bean scopes in Spring have you used in your projects?
sobes.tech AI
Answer from AI
The most commonly used bean scopes in Spring are:
- singleton — a bean is created once for the entire Spring container and reused. This is the default scope.
- prototype — a new instance of the bean is created each time it is requested.
- request — the bean exists for the duration of a single HTTP request (used in web applications).
- session — the bean lives within the user's HTTP session.
- application — the bean exists within the ServletContext, i.e., for the entire lifecycle of the web application.
In my projects, I most often used singleton for services and components, prototype for stateful objects, and request and session in web applications for storing data tied to the request or user session.