Spring shell with groovy

54 Views Asked by At

I have my class:

package com.ejemplo.prueba;

import org.springframework.shell.standard.ShellComponent
import org.springframework.shell.standard.ShellMethod

@ShellComponent
class MyShellCommands {

    @ShellMethod("Este es un comando de ejemplo")
    def myCommand() {
        return "¡Hola desde Groovy!"
    }
}

But when I execute the shell, it's fail:

shell:>myCommand No command found for 'myCommand'

My depencies maven in pom are:

Springoot 3.1.4 and Spring shell 3.1.3 and

The execution in shell should show:

¡Hola desde Groovy!

1

There are 1 best solutions below

0
J Asgarov On

As can be seen in documentation if you don't specify the key attribute of @ShellMethod annotation, then per default you camelCase myCommand gets converted to kebap case (my-command).

  • Either define it yourself: @ShellMethod(key = "myCommand", value = "Este es un comando de ejemplo")
  • or use the auto generated version my-command from the commandline.

Try also using help to see the list of available commands