Question: A bean's scope determines how the bean behaves when that bean is requested from the ApplicationContext - Spring * could be instructed to either provide
A bean's scope determines how the bean behaves when that bean is requested from the ApplicationContext Spring
could be instructed to either provide a newlyinstantiated object or reuse an existing object. Below are the
Spring bean scopes:
Singleton the default scope, any time a specific bean is requested, the existing object is reused
Prototype any time a bean is requested a new object is instantiated
Request only used in web applications a new object is instantiated once per web request
Session only used in web applications a new object is instantiated once per web session
Application only used in web applications a new object is instantiated once per web servlet
Websocket only used in web applications a new object is instantiated once per websocket
The @Scope annotation here is unnecessary as "singleton" is the default, but this example shows how the
scope can be set.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
