加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – spring boot远程shell自定义命令

发布时间:2020-12-15 00:43:30 所属栏目:Java 来源:网络整理
导读:我尝试向 spring boot远程shell添加一个新的自定义命令,但没有成功. 在文档中只有一个groovy示例可用,但我喜欢使用 Java创建一个新命令. http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-remote-shell.html 我还查看了CRaS
我尝试向 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";
  }
}

解决方法

如果你的班级被称为’你好’,请把它放进去
resources/crash/commands/hello/hello.java

包语句无关紧要.
你不必在src中放任何东西,只需要在内部资源中.

@Component不是必需的.

该类在运行时编译.看到:

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

因此,需要使用延迟初始化来考虑任何依赖注入要求.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读