上下文关闭

命令执行逻辑通过 Spring Boot 的ApplicationRunner bean 来实现。通常情况下,除非有一些东西让它保持活动状态,例如使用@EnableScheduling或通常情况下有一些线程不会自动结束,否则 Spring ApplicationContext会在这些 runner bean 处理完毕后自动关闭。

可以添加配置属性spring.shell.context.close,它会为ApplicationReadyEvent注册一个ApplicationListener,并在 shell 完成其执行逻辑后请求关闭上下文。

spring:
  shell:
    context:
      close: true
此设置默认情况下未启用。