> For the complete documentation index, see [llms.txt](https://potoyang.gitbook.io/spring-in-action-v4/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://potoyang.gitbook.io/spring-in-action-v4/untitled-14/untitled-4/untitled-1.md).

# 21.1.3　Spring Boot CLI

Spring Boot CLI 充分利用了 Spring Boot Starter 和自动配置的魔力，并添加了一些 Groovy 的功能。它简化了 Spring 的开发流程，通过 CLI，我们能够运行一个或多个 Groovy 脚本，并查看它是如何运行的。在应用的运行过程中，CLI 能够自动导入 Spring 类型并解析依赖。

用来阐述 Spring Boot CLI 的最有趣的例子就是如下的 Groovy 脚本：

```groovy
@RestController
class Hi {
  @RequestMapping("/")
  String hi() {
    "Hi!"
  }
}
```

不管你是否相信，这是一个完整的（尽管比较简单）Spring 应用，它可以在 Spring Boot CLI 中运行。包括空格，它的长度只有 82 个字符。 你可以将其粘贴到 Twitter 客户端，并分享给你的朋友们。

去掉不必要的空格，我们能够得到只有 64 个字符的一行代码：

```groovy
@RestController class Hi{@RequestMapping("/")String hi(){"Hi!"}}
```

这个版本更加简单，在一条 Twitter 的推文中，我们可以粘贴两次。但它依然是一个完整可运行的（尽管特性比较简陋）Spring 应用。如果你已经安装过 Spring Boot CLI，我们可以使用如下的命令行来运行它：

```bash
$ spring run Hi.groovy
```

以推文的形式来展示 Spring Boot CLI 的功能是很有意思的，但是它所能做的事情并不仅限于我们所看到的这些。在 21.3 小节中，我们将会看到如何使用 Groovy 和 CLI 构建更加完整的应用。
