spring_reference/V. Spring Boot Actuator/43.2.1. Remote shell comman...

34 lines
982 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 43.2.1. 远程shell命令
你可以使用Groovy或Java编写其他的shell命令具体参考CRaSH文档。默认情况下Spring Boot会搜索以下路径的命令
* `classpath*:/commands/**`
* `classpath*:/crash/commands/**`
**注**:可以通过`shell.commandPathPatterns`属性改变搜索路径。
下面是一个从`src/main/resources/commands/hello.groovy`加载的'hello world'命令:
```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|