Sep 29th, 2012, 02:59 AM
Query about Bean scope
I have a question about bean scoping.
As per my understanding spring container loads all beans declared in springContext.xml(application context in my case) when application get started.
Now in case of prototype bean, for each request to a particular bean I am getting a complete new object. This mean that container is creating a new bean(object) at run time.
So it would be helpful if anyone can explain me the exact working behaviour of spring container.
Thanks in advance.
Sep 29th, 2012, 02:26 PM
Singleton beans are created on startup by default (you can use "lazy" attribute to create them when they are accessed for the first time). There is only one instance of each singleton of course.
As you said, prototype scope means that a new instance of a bean is created every time when it is requested (ctx.getBean(..), injection into another bean).
Other scopes that Spring provides are bound to some resource, like http request or session. It means e.g. that for the same http request, the same instance of bean is always returned when requested.
It is described in detail in the Spring reference documentation, here.
Sep 30th, 2012, 12:33 AM