标签搜索

目 录CONTENT

文章目录

SpringBoot应用优雅上下线

陈铭
2023-06-05 / 0 评论 / 0 点赞 / 154 阅读 / 52 字 / 正在检测是否收录...

上线

@Component
public class GracefulStartupListener implements ApplicationListener<ApplicationReadyEvent> {    
    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent){
       //注册逻辑 优雅上线
       apiRegister.register(urls);
       ...
    }
}

下线

@Component
public class GracefulShutdownListener implements ApplicationListener<ContextClosedEvent> {

    @Override
    public void onApplicationEvent(ContextClosedEvent contextClosedEvent){
       //注销逻辑
       zookeeperRegistry.unregister(mCurrentServiceURL);
       ...
    }
}
0

评论区