> For the complete documentation index, see [llms.txt](https://cwiki-us.gitbook.io/spring-boot-reference-guide-zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cwiki-us.gitbook.io/spring-boot-reference-guide-zh/v.-spring-boot-actuator/49.-monitoring-and-management-using-a-remote-shell/49.2-extending-the-remote-shell/49.2.1-remote-shell-commands.md).

# 49.2.1 远程shell命令

你可以使用Groovy或Java编写其他的shell命令（具体参考CRaSH文档），Spring Boot默认会搜索以下路径的命令：

* `classpath*:/commands/**`
* `classpath*:/crash/commands/**`

**注** 设置`shell.command-path-patterns`属性可以改变搜索路径。 **注** 如果使用可执行存档（archive），shell依赖的所有类都必须打包进一个内嵌的jar，而不是直接打包进可执行jar或war。

下面是一个从`src/main/resources/commands/hello.groovy`加载的'hello'命令：

```java
package commands

import org.crsh.cli.Usage
import org.crsh.cli.Command

class hello {

    @Usage("Say Hello")
    @Command
    def main(InvocationContext context) {
        return "Hello"
    }

}
```

Spring Boot为`InvocationContext`添加一些其他属性，你可以在命令中访问它们：

| 属性名称                  | 描述                     |
| --------------------- | ---------------------- |
| `spring.boot.version` | Spring Boot的版本         |
| `spring.version`      | Spring核心框架的版本          |
| `spring.beanfactory`  | 获取Spring的`BeanFactory` |
| `spring.environment`  | 获取Spring的`Environment` |
