Middle
What cache types of beans have you used in Spring? What is the purpose of the prototype?
sobes.tech AI
Answer from AI
The following main bean scopes are used in Spring:
- Singleton (default) — one instance per Spring container.
- Prototype — a new instance is created each time the bean is requested.
- Request — one instance per HTTP request (in web applications).
- Session — one instance per HTTP session.
- Application — one instance per ServletContext.
The prototype scope is used when a new bean instance is needed on each request, for example, for state that should not be shared between calls or threads. This is useful for beans with mutable state that should not be singletons.