I am implementing the DisposableBean in one of my beans to get notified when my server is shutting down. However, the destroy method is never called.
I am running Tomcat with S开发者_C百科pring 3.
Any suggestions?
Use ContextLoaderListener and override contextDestroyed method. 
Don't forget to declare ContextLoaderListener in your web.xml.
Instead of using ApplicationContext, use AbstractApplicationContext. Then register the same. Spring wont call DisposableBean for desktop application if you are using ApplicationContext.
Ex: AbstractApplicationContext appCxt= new ClassPathXmlApplicationContext("spring.xml"); appCxt.registerShutdownHook();
I tried this option.
With obj object with destroy() method, add this:
Runtime.getRuntime ( ).addShutdownHook ( new Thread ( obj::destroy ) );
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论