Issue
Below are the definitions of prototype and request scope in Spring.
prototype Scopes a single bean definition to any number of object instances.
request Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.
As per my understanding In case of prototype scope , some pool will be maintained by core container. It will serve the bean instance from that pool. In case of request scope, new bean will be served for each http request. Please correct me if there is some dicrepency in understanding?
If above statements are true, then if bean is holding some state then the scope should not be defined as prototype rather it should be defined as request. Correct?
Solution
You are off. Prototype is described in the docs here as
"The non-singleton, prototype scope of bean deployment results in the creation of a new bean instance every time a request for that specific bean is made."
Your description of request scoped beans is accurate.
Probably just got the wires crossed vis-a-vis prototype vs singleton.
Answered By - hvgotcodes
Answer Checked By - Robin (JavaFixing Admin)