Java – spring boot remote shell custom command
I tried to add a new custom command to the spring boot remote shell, but failed
http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-remote-shell.html I also looked at the crash document: http://www.crashub.org/1.3/reference.html#_java_commands
I put my classes in package commands and crash Commands, but if I connect to the shell via SSH and type help, I won't see my new command You know what I did wrong?
This 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"; } }
Solution
If your class is called 'hello', please put it in
resources/crash/commands/hello/hello.java
Package statements do not matter You don't have to put anything in SRC, just in internal resources
@Component is not required
This class is compiled at run time See:
org.crsh.lang.impl.java.JavaCompiler#compileCommand
Therefore, delayed initialization is needed to consider any dependency injection requirements