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