【发布时间】:2014-11-29 20:11:24
【问题描述】:
我尝试向 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 并输入帮助,我看不到我的新命令。知道我做错了什么吗?
这是我的 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";
}
}
【问题讨论】:
-
Spring Boot shell 扩展将命令视为 Groovy 脚本,而不是 Spring bean。无论如何,您的 Java 代码通常都可以用作 Groovy;只需包含源代码而不是编译的
.class文件。