您可以尝试通过以下方式捕获JVM关闭事件:
Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.out.println("BYE BYE"); } });另一个选择是使用 @WebListener Annotation 实现ServletContextListener
。在这种情况下,不需要xml配置。
@WebListenerpublic class MyLifeCycleListener implements ServletContextListener { public void contextInitialized(ServletContextEvent event) { //TODO ON START } public void contextDestroyed(ServletContextEvent event) { //TODO ON DESTROY }}


