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.关闭监听 @Controller public static class ShutdownAction implements ApplicationListener<ContextClosedEvent> { @Override public 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 关闭服务 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Eclipse新建项目不可选择Java Project问题解决方案
这篇文章主要介绍了Eclipse新建项目不可选择Java Project问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-07-07Spring Boot Gradle发布war到tomcat的方法示例
本篇文章主要介绍了Spring Boot Gradle发布war到tomcat的方法示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-03-03SpringBoot整合Security实现权限控制框架(案例详解)
Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框,是一个重量级的安全管理框架,本文给大家介绍的非常详细,需要的朋友参考下吧2021-08-08
最新评论