spring boot 如何優(yōu)雅關閉服務
spring boot 優(yōu)雅的關閉服務
實現ContextClosedEvent 監(jiān)聽器,監(jiān)聽到關閉事件后,關閉springboot進程
**
網上有很多例子 使用spring boot 插件做關閉經測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現關閉監(jiān)聽,去殺死進程。
網上有很多例子 使用spring boot 插件做關閉經測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現關閉監(jiān)聽,去殺死進程。
網上有很多例子 使用spring boot 插件做關閉經測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現關閉監(jiān)聽,去殺死進程。
重要的事說三遍
**
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.關閉監(jiān)聽
@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 如何優(yōu)雅關閉服務的文章就介紹到這了,更多相關spring boot 關閉服務 內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Java toString方法重寫工具之ToStringBuilder案例詳解
這篇文章主要介紹了Java toString方法重寫工具之ToStringBuilder案例詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下2021-08-08
Java畢業(yè)設計實戰(zhàn)項目之倉庫管理系統(tǒng)的實現流程
這是一個使用了java+SSM+Maven+Bootstrap+mysql開發(fā)的倉庫管理系統(tǒng),是一個畢業(yè)設計的實戰(zhàn)練習,具有一個倉庫管理系統(tǒng)該有的所有功能,感興趣的朋友快來看看吧2022-01-01
Spring用AspectJ開發(fā)AOP(基于Annotation)
這篇文章主要介紹了Spring用AspectJ開發(fā)AOP(基于Annotation),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-10-10
request.getParameter()方法的簡單理解與運用方式
在JavaWeb開發(fā)中,request對象扮演著至關重要的角色,它是HTTP請求的封裝,request.getParameter()用于獲取客戶端通過GET或POST方式發(fā)送的參數,與之相對,request.setAttribute()用于在服務器端設置屬性,這些屬性只在一次請求中有效2024-10-10
Gitlab CI-CD自動化部署SpringBoot項目的方法步驟
本文主要記錄如何通過Gitlab CI/CD自動部署SpringBoot項目jar包。文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-07-07

