Share on Google+Share on Google+

The registerShutdownHook in spring

In this tutorial you will learn about Register Shutdown Hook of Spring Framework

The registerShutdownHook in spring

If you are using Spring IoC in non web application and want to gracefully downdown all resources we use registerShutdownHook(). This method calls the relevant destroy methods. In order to register a shutdown hook, you have to call the the registerShutdownHook() method which found in the AbstractApplicationContext class.

package com.roseindia.common;


public class AppMain {
	public static void main(String[] args) {
		AbstractApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "context.xml" });
		System.out.println("Add a shutdown hook for the above context");


<beans xmlns=""

When you run this application it will display message as shown below:

Add a shutdown hook for the above context
Sep 3, 2010 3:04:24 PM doClose
INFO: Closing org[email protected]18a47e0: startup date [Fri Sep 03 15:04:24 GMT+05:30
2010]; root of context hierarchy

Download this example code



Posted on: September 3, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null