public class ShutdownHookDemo { public static void main(String[] args) throws IOException { XmlBeanFactory factory = new XmlBeanFactory( new ClassPathResource("/META-INF/spring/lifecycledemo5-context.xml")); Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook(factory))); new BufferedInputStream(System.in).read(); } } public class ShutdownHook implements Runnable { private ConfigurableListableBeanFactory beanFactory; public ShutdownHook(ConfigurableListableBeanFactory beanFactory) { Assert.notNull(beanFactory, "The 'beanFactory' argument must not be null."); this.beanFactory = beanFactory; } public void run() { this.beanFactory.destroySingletons(); } }
this.beanFactory.destroySingletons()
最新推荐文章于 2023-03-20 09:52:04 发布