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

