java - 带有命令行运行器界面的 Spring shell
问题描述
我在运行 Spring Boot Spring Shell 应用程序时遇到问题。我已经实现了 commandlinerunner,但它从未在应用程序启动期间调用过。
@Component
public class ParamReader implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
if(args.length>0) {
System.out.println(Arrays.asList(args).stream().collect(Collectors.joining(", ")));
}
}
}
当我从 shell 运行 exit 命令时,它调用 run 方法,然后程序终止。我尝试在 Spring 应用程序主类上实现 commandlinerunner,但结果是一样的。
解决方案
Spring shell 使用ApplicationRunner
with@Order
注释和precedence 0
. 您可以尝试以下方法:
@Order(-1)
@Component
public class ParamReader implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
if(args.length>0) {
System.out.println(Arrays.asList(args).stream().collect(Collectors.joining(", ")));
}
}
}
推荐阅读
- java - 带有 h2 和 jooq 的 JdbcSQLSyntaxErrorException
- python - 计算多标签分类 keras 的召回精度和 F1 分数
- wxpython - wxPython:使用 TextEditMixin 选择文本时出现问题
- linux - 特定组访问文件/目录 linux
- java - 活动如何监听其他类的事件
- flutter - CupertinoContextMenu previewBuilder 或子小部件在全屏视图中未重建,setState() 在 dispose() 后调用:关闭时出错
- typescript - 如何理解 Typescript 错误消息?
- javascript - 如何处理单个数组上的多个异步调用?
- python - 从每个列表中获取一个元素,随机数量的列表
- postgresql - postgresql 序列和休眠的问题