Junior — Middle
Can you list the types of component scope in Spring Framework?
sobes.tech AI
Answer from AI
In the Spring Framework, the following main component (bean) scopes are available:
- singleton — the default. One bean instance is created in the Spring container for the entire application context.
- prototype — a new bean instance is created each time it is requested.
- request — the bean lives within a single HTTP request (relevant for web applications).
- session — the bean lives within an HTTP session.
- application — the bean lives within the ServletContext (web application).
- websocket — the bean lives within a WebSocket session.
Example of specifying scope:
@Component
@Scope("prototype")
public class MyBean {
// ...
}