spring boot 如何優(yōu)雅關(guān)閉服務(wù)
spring boot 優(yōu)雅的關(guān)閉服務(wù)
實(shí)現(xiàn)ContextClosedEvent 監(jiān)聽(tīng)器,監(jiān)聽(tīng)到關(guān)閉事件后,關(guān)閉springboot進(jìn)程
**網(wǎng)上有很多例子 使用spring boot 插件做關(guān)閉經(jīng)測(cè)試此插件只能是關(guān)閉spring boot服務(wù),不能殺死服務(wù)進(jìn)程。還是需要實(shí)現(xiàn)關(guān)閉監(jiān)聽(tīng),去殺死進(jìn)程。網(wǎng)上有很多例子 使用spring boot 插件做關(guān)閉經(jīng)測(cè)試此插件只能是關(guān)閉spring boot服務(wù),不能殺死服務(wù)進(jìn)程。還是需要實(shí)現(xiàn)關(guān)閉監(jiān)聽(tīng),去殺死進(jìn)程。網(wǎng)上有很多例子 使用spring boot 插件做關(guān)閉經(jīng)測(cè)試此插件只能是關(guān)閉spring boot服務(wù),不能殺死服務(wù)進(jìn)程。還是需要實(shí)現(xiàn)關(guān)閉監(jiān)聽(tīng),去殺死進(jìn)程。重要的事說(shuō)三遍**
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中開(kāi)啟關(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)聽(tīng)@Controllerpublic static class ShutdownAction implements ApplicationListener<ContextClosedEvent> {@Overridepublic 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)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. python爬蟲(chóng)實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊2. Ajax返回值類(lèi)型與用法實(shí)例分析3. .NET6打包部署到Windows Service的全過(guò)程4. Vue element ui用戶(hù)展示頁(yè)面的實(shí)例5. 如何在jsp界面中插入圖片6. HTML 絕對(duì)路徑與相對(duì)路徑概念詳細(xì)7. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)財(cái)務(wù)記賬管理系統(tǒng)8. asp批量添加修改刪除操作示例代碼9. 使用FormData進(jìn)行Ajax請(qǐng)求上傳文件的實(shí)例代碼10. css代碼優(yōu)化的12個(gè)技巧
