久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

spring boot 如何優(yōu)雅關(guān)閉服務(wù)

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

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)測(cè)試此插件只能是關(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)測(cè)試此插件只能是關(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)測(cè)試此插件只能是關(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)聽@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)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 滨州市| 涟水县| 庆阳市| 阿坝| 潍坊市| 临漳县| 辽宁省| 德惠市| 徐州市| 乌拉特中旗| 察隅县| 临泉县| 清原| 蒙城县| 托克逊县| 永川市| 辽阳市| 简阳市| 清原| 静安区| 蓝山县| 武清区| 嫩江县| 凤山县| 马龙县| 申扎县| 新和县| 拉孜县| 罗山县| 浦城县| 东乡县| 嵊州市| 九台市| 彩票| 米泉市| 新兴县| 常山县| 理塘县| 来安县| 府谷县| 玉山县|