49.2 Extending the remote shell

The remote shell can be extended in a number of interesting ways.

49.2.1 Remote shell commands

You can write additional shell commands using Groovy or Java (see the CRaSH documentation for details). By default Spring Boot will search for commands in the following locations:

  • classpath*:/commands/**
  • classpath*:/crash/commands/**
[Tip] Tip
You can change the search path by settings a shell.command-path-patterns property.
[Note] Note
If you are using an executable archive, any classes that a shell command depends upon must be packaged in a nested jar rather than directly in the executable jar or war.

Here is a simple ‘hello’ command that could be loaded from src/main/resources/commands/hello.groovy

package commands

import org.crsh.cli.Command
import org.crsh.cli.Usage
import org.crsh.command.InvocationContext

class hello {

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

}

Spring Boot adds some additional attributes to InvocationContext that you can access from your command:

Attribute Name Description
spring.boot.version The version of Spring Boot
spring.version The version of the core Spring Framework
spring.beanfactory Access to the Spring BeanFactory
spring.environment Access to the Spring Environment

49.2.2 Remote shell plugins

In addition to new commands, it is also possible to extend other CRaSH shell features. All Spring Beans that extend org.crsh.plugin.CRaSHPlugin will be automatically registered with the shell.

For more information please refer to the CRaSH reference documentation.

results matching ""

    No results matching ""