0

我正在使用弹簧外壳,它工作正常。但我想在方法中运行一些内置命令,例如退出命令。
我怎样才能做到这一点?

@Component  
 public class runCommand implements CommandMarker {

    @CliCommand(value = "exit", help = "")
    public void exit() {
      // run exit built in command to exit
    }
}
4

2 回答 2

0
  1. 首先,您必须禁用该命令(在这种情况下退出)。
  2. 接下来通过扩展命令类创建一个子类。
  3. 接下来您可以从子类中调用命令方法。

这是一个例子:

class CustomClear extends Clear {
    @ShellMethod(value="myClear")
    public void customCommand(){
        super.clear();
    }

}
于 2019-06-21T10:02:06.007 回答
0

你可以参考这个,disabling_specific_commands

public static void main(String[] args) throws Exception {
        String[] disabledCommands = {"--spring.shell.command.exit.enabled=true"}; 
        String[] fullArgs = StringUtils.concatenateStringArrays(args, disabledCommands);
        SpringApplication.run(MyApp.class, fullArgs);
}
于 2017-11-30T12:35:26.263 回答