住房与建设部网站首页,ai建筑设计平台,广西营销型网站建设公司,wordpress 标签小工具栏SpringBoo在项目停止/服务停止/关闭退出之后执行的方法 1.实现DisposableBean接口2.使用PreDestroy注解 SpringApplication会向JVM注册一个关闭钩子(hook)#xff0c;以确保ApplicationContext在退出时正常关闭。 可以使用所有标准的Spring生命周期回调#xff08;例如Dispos… SpringBoo在项目停止/服务停止/关闭退出之后执行的方法 1.实现DisposableBean接口2.使用PreDestroy注解 SpringApplication会向JVM注册一个关闭钩子(hook)以确保ApplicationContext在退出时正常关闭。 可以使用所有标准的Spring生命周期回调例如DisposableBean接口或PreDestroy注解。 1.实现DisposableBean接口
Component
public class ImplDisposableBean implements DisposableBean, ExitCodeGenerator {Overridepublic void destroy() throws Exception {System.out.println(我被销毁了......................);}Overridepublic int getExitCode() {return 1;}
}2.使用PreDestroy注解
PreDestroy
public void PreDestroyComplete() {System.out.println(PreDestroyStart);
}