I've run aground when trying to do the Spring Shell Tutorial. I downloaded a basic application from Spring Intializr with the following properties:
I created it once for Java and once for Groovy.
I created a command file in both versions with identical contents:
package test.demo;
import org.springframework.shell.standard.*;
@ShellComponent
public class SampleCommands {
@ShellMethod(key = "hello-world")
public String helloWorld(
@ShellOption(defaultValue = "spring") String arg
) {
return "Hello world " + arg;
}
}
Both versions compile without trouble, and will list the hello-world
command when you run help
.
AVAILABLE COMMANDS
Built-In Commands
help: Display help about available commands
history: Display or save the history of previously run commands
version: Show version info
script: Read and execute commands from a file.
Sample Commands
hello-world:
The sample command works in the Java version.
Hello world spring
But it dies when you run the Groovy Version
java.lang.IllegalArgumentException: Name for argument of type [java.lang.String] not specified, and parameter name information not found in class file either.
at org.springframework.shell.support.AbstractArgumentMethodArgumentResolver.updateNamedValueInfo(AbstractArgumentMethodArgumentResolver.java:154) ~[spring-shell-core-3.3.0.jar!/:3.3.0]
at org.springframework.shell.support.AbstractArgumentMethodArgumentResolver.getNamedValueInfo(AbstractArgumentMethodArgumentResolver.java:129) ~[spring-shell-core-3.3.0.jar!/:3.3.0]
...and much, much more....
What am I doing wrong?
So, error is saying can't find name for a string parameter
Name for argument of type [java.lang.String] not specified, and parameter name information not found in class file either.
My guess that you are using older version of groovy compiler that does not support (or hides) argument names.
But you can define an argument name with annotation attribute value="..."
:
public String helloWorld(
@ShellOption(defaultValue = "spring", value="arg") String arg
) {
return "Hello world " + arg;
}