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