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.
AppMain.java
package com.roseindia.common;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
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");
context.registerShutdownHook();
}
}
context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
|
| Add a shutdown hook for the above context Sep 3, 2010 3:04:24 PM org.springframework.context.support.AbstractApplicationContext doClose INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@18a47e0: startup date [Fri Sep 03 15:04:24 GMT+05:30 2010]; root of context hierarchy |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.