上下文關閉
命令執行邏輯透過 Spring Boot 的 ApplicationRunner
bean 實現。通常情況下,除非有像使用 @EnableScheduling
這樣保持上下文活躍的機制,或者通常來說存在不會自動終止的執行緒,否則 Spring ApplicationContext
會在這些 runner bean 處理完成後自動關閉。
可以透過新增配置屬性 spring.shell.context.close
來註冊一個針對 ApplicationReadyEvent
的 ApplicationListener
,並在 shell 完成執行邏輯後請求關閉上下文。
spring:
shell:
context:
close: true
此設定預設不啟用。 |