HRS - Ask. Learn. Share Knowledge. Logo

In Computers and Technology / High School | 2025-07-08

Choose the default bean scope for any Spring Bean. (A) Singleton (B) Request (C) Global (D) Prototype (E) Session

Asked by gjbgbv5182

Answer (1)

In Spring Framework, which is widely used in Java for dependency injection and managing the lifecycle of objects, the default scope for any Spring Bean is Singleton . This means that when a bean is defined with the default scope, Spring creates only one instance of this bean per Spring container, and this single instance is shared and reused whenever it is needed.
Here is a brief explanation of the bean scopes for better understanding:

Singleton : The default scope. Spring creates one instance per Spring container. The same instance will be returned by all calls to the container.

Prototype : A new instance is created each time a bean is requested. This is contrary to Singleton scope.

Request : In a web application, a new instance is created for each HTTP request. This scope is valid only in a web-aware Spring ApplicationContext.

Session : A new bean instance is created for each session. Like the Request scope, this is also valid in a web environment.

Global Session : This is used for Portlet-based applications, similar to the Session scope but for a global Portlet session.


To summarize, the correct choice for the default bean scope in Spring is (A) Singleton.

Answered by OliviaMariThompson | 2025-07-22