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)測(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)!
相關(guān)文章:
1. js實(shí)現(xiàn)跳一跳小游戲2. JVM之class文件結(jié)構(gòu)3. js實(shí)現(xiàn)貪吃蛇小游戲(加墻)4. PHP設(shè)計(jì)模式(四)原型模式Prototype實(shí)例詳解【創(chuàng)建型】5. 使用idea 去除 html 代碼前的行號(hào)和空行的方法詳解6. 10個(gè)提供免費(fèi)PHP腳本下載的網(wǎng)站7. php5.6不能擴(kuò)展redis.so的解決方法8. SpringBoot 開發(fā)提速神器 Lombok+MybatisPlus+SwaggerUI9. Python編寫nmap掃描工具10. python 爬取嗶哩嗶哩up主信息和投稿視頻
