对于最新的稳定版本,请使用 Spring Shell 3.3.3spring-doc.cadn.net.cn

执行

本节介绍如何设置 Spring Shell 以在交互模式下工作。spring-doc.cadn.net.cn

交互模式

版本 2.1.x 引入了内置支持,以区分交互式 和非交互模式。这使得将 shell 用作 简单的命令行工具,无需自定义。spring-doc.cadn.net.cn

目前,如果在启动时传递了任何命令行选项,则会进入交互模式 或从命令行运行 shell。这在 shell 应用程序 是使用 Native Support 编译的。spring-doc.cadn.net.cn

某些命令在交互模式下运行时可能没有任何有用的含义 或(相反)在非交互模式下。例如,内置的exit命令将 在非交互模式下没有意义,因为它用于退出交互模式。spring-doc.cadn.net.cn

@ShellMethodannotation 有一个名为interactionMode您可以使用它来通知 shell 来了解特定命令何时可用。spring-doc.cadn.net.cn

Shell Runners

ShellApplicationRunner是一个主界面,其中 Boot 的ApplicationArguments传递 ,它的默认实现会选择一个ShellRunner被使用。可以有 只有一个ShellApplicationRunner但是如果出于某种原因需要,可以重新定义它。spring-doc.cadn.net.cn

ShellRunnerimplementation 存在,名为InteractiveShellRunner,NonInteractiveShellRunnerScriptShellRunner.这些默认启用,但 如果需要,可以使用 properties 禁用spring.shell.interactive.enabled,spring.shell.noninteractive.enabledspring.shell.script.enabled具体地。spring-doc.cadn.net.cn


APP信息