Search code examples
javaspringjakarta-eespring-mvcobject-lifetime

Lifetime of object created using ApplicationContext.xml in Spring MVC


I am new to spring application...

I want to know, When the object created using applicationcontext.xml file will get destroyed?..

i.e., I want to know the life time of the object created by applicationcontext.xml file...

I tried a lot in Google search but I can't able to find out solution.. All suggestions are towards the Scope of bean.. Is that scope determines the lifetime?

How to find out lifetime of object and when ll it get destroyed in Spring MVC?...

Thanks in advance and expects to get resolve soon... Please help me out..


Solution

  • Spring will destroy the objects (only Singletons) when the applicationContext is closed.

    From Doc

    A BeanFactory is supposed to invoke the destroy method if it disposes a cached singleton. An application context is supposed to dispose all of its singletons on close.

    Comment from Spring Team member

    One thing to note is that Spring doesn't track prototypes/scoped beans - it only tracks singletons and as a result, the destroy method will be called only on singletons.

    Source : http://forum.springsource.org/showthread.php?32253-When-will-the-bean-s-destroy-method-be-invoked