弹簧启动远程shell自定义命令

我尝试将新的自定义命令添加到spring引导远程shell中,但未成功。 在文档中只是一个可用的例子,但我喜欢使用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";
  }
} 

如果你的班级被称为“你好”,就把它放进去

resources/crash/commands/hello/hello.java

有一个包装声明并不重要。 你不必把任何东西放在src里面,只需要这个内部资源。

@Component不是必需的。

这个类是在运行时编译的。 看到:

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

因此,任何依赖注入需求都需要相应地考虑延迟初始化。


将类放入默认包(即省略包语句),并将类的Java源代码放入src / main / resources / commands中。 第一次调用命令时,Spring / Crash会编译Java代码。 另外,如果类实现单个命令,那么方法名应该是'main',否则用户必须输入:

> hello test

您也不需要该类的@Component注释,因为它不是Spring托管bean。

链接地址: http://www.djcxy.com/p/23075.html

上一篇: spring boot remote shell custom command

下一篇: How to properly read POST request body in a Handler?