我尝试向spring boot远程shell添加一个新的自定义命令,但没有成功.在文档中只有一个groovy示例可用,但我喜欢使用Java创建一个新命令.
http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-remote-shell.html 我还查看了CRaSH文档:http://www.crashub.org/1.3/ #的reference.html _java_commands
我把我的类放在包命令和crash.commands下,但如果我通过ssh连接到shell并输入help,我看不到我的新命令.知道我做错了什么吗?
这是我的Java代码:
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";
}
}
Run Code Online (Sandbox Code Playgroud)
将类放入默认包中(即省略 package 语句)并将该类的 Java 源代码放入 src/main/resources/commands 中。Spring/Crash 将在您第一次调用该命令时编译 Java 代码。另外,如果该类实现单个命令,则方法名称应为 \xe2\x80\x98main\xe2\x80\x99,否则用户必须键入:
\n\n> hello test\nRun Code Online (Sandbox Code Playgroud)\n\n您也不需要在类上使用 @Component 注释,因为它不是 Spring 托管 bean。
\n