193k views
0 votes
What bean scopes does Spring support, and can you explain them?

a) Singleton, Prototype, Request, Session
b) Public, Private, Protected, Package-private
c) Static, Final, Abstract, Interface
d) Controller, Model, View

User Yin Yang
by
8.6k points

1 Answer

2 votes

Final answer:

Spring supports multiple bean scopes, including Singleton, Prototype, Request, and Session. These bean scopes define the lifecycle and visibility of a bean in a Spring application.

Step-by-step explanation:

Spring supports multiple bean scopes, including Singleton, Prototype, Request, and Session. These bean scopes define the lifecycle and visibility of a bean in a Spring application.

The Singleton scope creates a single instance of a bean that is shared across the entire application. The Prototype scope creates a new instance of a bean each time it is requested. The Request scope creates a new instance of a bean for each HTTP request, and the Session scope creates a new instance of a bean for each user session.

Each scope has its own use case, and it's important to understand the differences and choose the appropriate scope for each bean in your application.

User Kanishk Anand
by
7.6k points