Spring user shell remote boot command

I am trying to add a new custom command to the remote spring boot shell without success. Only the groovy example is available in the documentation, but I like to use Java to create a new command.

http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-remote-shell.html I also check CRaSH documentation: http://www.crashub.org/1.3/reference .html # _java_commands

I put my class under the package and crash.commands commands, but I don't see my new command if I connect to the shell using ssh help and type. Any idea what I'm doing wrong?

Here is my Java code:

package commands; import org.crsh.cli.Command; import org.crsh.cli.Usage; import org.crsh.command.BaseCommand; import org.springframework.stereotype.Component; @Component public class hello extends BaseCommand { @Command @Usage("Say Hello") public String test() { return "HELLO"; } } 
+7
java spring shell
source share
2 answers

If your class is called hello, put it in

 resources/crash/commands/hello/hello.java 

The presence of a package instruction does not matter. You do not need to enter anything inside src, just use these internal resources.

@ Component not required.

This class compiles at runtime. Cm:

 org.crsh.lang.impl.java.JavaCompiler#compileCommand 

Therefore, any requirements for dependency injection must be considered accordingly with lazy initialization.

+2
source share

Put the class in the default package (i.e. omit the package operator) and put the Java source for the class in the src / main / resources / commands. Spring / Crash compiles Java code the first time the command is called. In addition, if the class implements one command, the method name must be "main, otherwise users must enter:

 > hello test 

You also do not need the @Component annotation for the class, since it is not a Spring bean.

+1
source share

All Articles