spring boot 如何优雅关闭服务
springboot优雅的关闭服务
实现ContextClosedEvent监听器,监听到关闭事件后,关闭springboot进程
**
网上有很多例子使用springboot插件做关闭经测试此插件只能是关闭springboot服务,不能杀死服务进程。还是需要实现关闭监听,去杀死进程。
网上有很多例子使用springboot插件做关闭经测试此插件只能是关闭springboot服务,不能杀死服务进程。还是需要实现关闭监听,去杀死进程。
网上有很多例子使用springboot插件做关闭经测试此插件只能是关闭springboot服务,不能杀死服务进程。还是需要实现关闭监听,去杀死进程。
重要的事说三遍
**
actuator关闭springboot实现方式
引入actuator配置shutdown
调用http://127.0.0.1/xxx/
引入actuator--> org.springframework.boot spring-boot-starter-actuator
配置
在application.properties中开启关闭
management.endpoints.web.exposure.include=*
#management.endpoint.shutdown.enabled=true
1.调用
1.主入口
publicstaticConfigurableApplicationContextconfigurableApplicationContext;
publicstaticvoidmain(String[]args)throwsInterruptedException{
configurableApplicationContext=SpringApplication.run(GatewayApplication.class,args);
}
2.关闭监听
@Controller
publicstaticclassShutdownActionimplementsApplicationListener{
@Override
publicvoidonApplicationEvent(ContextClosedEventevent){
System.exit(SpringApplication.exit(configurableApplicationContext));
}
}
3.关闭服务命令
/**
*关闭服务
*/
@RequestMapping(value="/stop",method=RequestMethod.GET)
@ResponseBody
publicvoidstopServer(){
MySpringApplication.configurableApplicationContext.close();
}
到此这篇关于springboot如何优雅关闭服务的文章就介绍到这了,更多相关springboot关闭服务内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下