spring boot 如何優(yōu)雅關閉服務
spring boot 優(yōu)雅的關閉服務
實現(xiàn)ContextClosedEvent 監(jiān)聽器,監(jiān)聽到關閉事件后,關閉springboot進程
**網(wǎng)上有很多例子 使用spring boot 插件做關閉經(jīng)測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現(xiàn)關閉監(jiān)聽,去殺死進程。網(wǎng)上有很多例子 使用spring boot 插件做關閉經(jīng)測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現(xiàn)關閉監(jiān)聽,去殺死進程。網(wǎng)上有很多例子 使用spring boot 插件做關閉經(jīng)測試此插件只能是關閉spring boot服務,不能殺死服務進程。還是需要實現(xiàn)關閉監(jiān)聽,去殺死進程。重要的事說三遍**
actuator 關閉spring boot 實現(xiàn)方式引入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.關閉監(jiān)聽@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 如何優(yōu)雅關閉服務的文章就介紹到這了,更多相關spring boot 關閉服務 內容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!
相關文章:

網(wǎng)公網(wǎng)安備