Spring bean's DESTROY-METHOD attribute and web-application "prototype"d bean

Posted by EugeneP on Stack Overflow See other posts from Stack Overflow or by EugeneP
Published on 2010-05-11T10:16:52Z Indexed on 2010/05/11 10:34 UTC
Read the original article Hit count: 349

Filed under:
|
|
|

Can get work the attribute "destroy-method".

First, even if I type non-existing method name into "destroy-method" attribute,

Spring initialization completes fine (already strange!).

Next, when a bean has a "prototype" scope, then I suppose it must be destroyed before the application

is closed. That not happens, it is simply never called in my case.

Though, after extracting this bean I can call this method explicitly and it does its job.

Could you explain why this method is never called in my Spring 2.5 case?

p.s. The method exists, it is public and has no arguments.

It seems to be a more difficult task then I thought.

The problem is that this destroy method is called whenever the context is closed, and this is a rare case.

My question is this:

I have a web app. I have a "prototype"-scoped bean.

What I need is when the current session is closed, this destroy method was automatically called by Spring.

I can do it by hand, but is there any solution how to make Spring do this job? It destroys the bean after the session is destroyed, it might be possible for Spring to call a method on that bean before destroying it?

© Stack Overflow or respective owner

Related posts about java

Related posts about spring