国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

spring boot 如何優雅關閉服務

瀏覽:3日期:2023-08-03 13:21:09

spring boot 優雅的關閉服務

實現ContextClosedEvent 監聽器,監聽到關閉事件后,關閉springboot進程

**網上有很多例子 使用spring boot 插件做關閉經測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現關閉監聽,去殺死進程。網上有很多例子 使用spring boot 插件做關閉經測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現關閉監聽,去殺死進程。網上有很多例子 使用spring boot 插件做關閉經測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現關閉監聽,去殺死進程。重要的事說三遍**

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.關閉監聽@Controllerpublic static class ShutdownAction implements ApplicationListener<ContextClosedEvent> {@Overridepublic 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 如何優雅關閉服務的文章就介紹到這了,更多相關spring boot 關閉服務 內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 万全县| 谷城县| 凤凰县| 吉林市| 兴仁县| 葫芦岛市| 健康| 鄂尔多斯市| 三河市| 桑日县| 三台县| 蓝山县| 安塞县| 天等县| 揭阳市| 无锡市| 乾安县| 武宣县| 镇坪县| 雷波县| 夏津县| 莱阳市| 景谷| 台东县| 和林格尔县| 赤城县| 望谟县| 襄垣县| 安图县| 潜江市| 大埔区| 仙桃市| 申扎县| 盐边县| 四川省| 砀山县| 商丘市| 邵武市| 连南| 山阳县| 南华县|