独立(非网络)应用程序中的registerShutdownHook():
在
@PreDestroy上豆方法用于注释当豆被从上下文移除或当所述上下文被关闭时得到通知。
当
context.close()或被
context.registerShutdownHook()调用时,将触发关闭事件。
@Component(value="someBean")public class SomeBean { @PreDestroy public void destroy() { System.out.println("Im inside destroy..."); }}我希望你已经知道这一点。
Web应用程序中的registerShutdownHook():
在Web应用程序中,DispatcherServlet /
ContextListener创建ApplicationContext,并在服务器关闭时关闭上下文。你 并不
需要显式调用
context.close()或
context.registerShutdownHook()。
当服务器关闭时,
@PreDestorybean上的方法将自动得到通知。



