sree
sree

Reputation: 535

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..

Upvotes: 3

Views: 1070

Answers (2)

Ajinkya
Ajinkya

Reputation: 22720

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

Upvotes: 1

Abdullah Shaikh
Abdullah Shaikh

Reputation: 2604

Yes scope determines the lifetime. Look at the different bean scopes available

Upvotes: 0

Related Questions