spring boot 如何优雅关闭服务
spring boot 优雅的关闭服务
实现ContextClosedEvent 监听器,监听到关闭事件后,关闭springboot进程
**网上有很多例子 使用spring boot 插件做关闭经测试此插件只能是关闭spring boot服务,不能杀死服务进程。还是需要实现关闭监听,去杀死进程。网上有很多例子 使用spring boot 插件做关闭经测试此插件只能是关闭spring boot服务,不能杀死服务进程。还是需要实现关闭监听,去杀死进程。网上有很多例子 使用spring boot 插件做关闭经测试此插件只能是关闭spring boot服务,不能杀死服务进程。还是需要实现关闭监听,去杀死进程。重要的事说三遍**
actuator 关闭spring boot 实现方式引入actuator 配置 shutdown调用http://127.0.0.1/xxx/
引入actuator<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>-->
配置在application.properties中开启关闭management.endpoints.web.exposure.include=*#management.endpoint.shutdown.enabled = true
1.调用
1.主入口public static ConfigurableApplicationContext configurableApplicationContext;public static void main(String[] args) throws InterruptedException { configurableApplicationContext = SpringApplication.run(GatewayApplication.class, args);}2.关闭监听@Controllerpublic static class ShutdownAction implements ApplicationListener<ContextClosedEvent> {@Overridepublic void onApplicationEvent(ContextClosedEvent event) {System.exit(SpringApplication.exit(configurableApplicationContext));}}3.关闭服务命令 /** * 关闭服务 */ @RequestMapping(value = '/stop', method = RequestMethod.GET) @ResponseBody public void stopServer() { MySpringApplication.configurableApplicationContext.close(); }
到此这篇关于spring boot 如何优雅关闭服务的文章就介绍到这了,更多相关spring boot 关闭服务 内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!
相关文章:
1. python GUI库图形界面开发之PyQt5中QWebEngineView内嵌网页与Python的数据交互传参详细方法实例2. python+excel接口自动化获取token并作为请求参数进行传参操作3. Vuex localStorage的具体使用4. docker /var/lib/docker/aufs/mnt 目录清理方法5. Python matplotlib画图时图例说明(legend)放到图像外侧详解6. 6个常见的 PHP 安全性攻击实例和阻止方法7. 《CSS3实战》笔记--渐变设计(三)8. Notepad++如何安装Python插件?Notepad++插件怎么装?9. ASP.NET泛型三之使用协变和逆变实现类型转换10. python tkinter实现下载进度条及抖音视频去水印原理

网公网安备