This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes spring shut down hook Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring shut down hook" Watch "spring shut down hook" New topic
Author

spring shut down hook

swapnel surade
Ranch Hand

Joined: Mar 05, 2009
Posts: 129
Hello,

I have standalone application , using spring ioc in that app.
This app is executed using command prompt. When user press ctrl+c or close the command prompt, I have to add shutdown hook.
So that i can call my customised bean method.
Is it possible to achieve this functionality using spring 2.0.

while searching I got following method which is called as
context.registerShutdownHook()

but how method mentioned above will call my method.

I've to use spring 2.0 only.

Thanks
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Yes this functionality was there in spring 2.

After creating your context you would immediately register your shutdown hook like you mentioned in your previous post. I think the part you are missing is using the spring life cycle events. What you want to do is on the bean definition that needs clean up define a destroy method using the 'destroy-method=' attribute. This method will be called when that bean is destoyed during the shutdown process which is initiated bythe shutdown hook you registered when the user ctrl-c to terminate the app.


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: spring shut down hook
 
Similar Threads
Is JavaFX not to late?
Java static Method
Logging username Using MethodInterceptor with AOP
Detect windows shutdown
Logging username Using MethodInterceptor with AOP