从Linux Terminal启动Spring Scheduled作业 [英] Start Spring Scheduled job from Linux Terminal

查看:152
本文介绍了从Linux Terminal启动Spring Scheduled作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我想从Linux Terminal启动Spring Scheduled作业.有什么方法可以从终端触发它吗?

I have a case where I want to start Spring Scheduled job from Linux Terminal. Is there some way to trigger it from the terminal?

例如,我可以使用Spring Shell启动计划作业吗?

For example can I use Spring Shell to start the Scheduled job?

推荐答案

我可以使用Spring Shell启动计划作业吗?

can I use Spring Shell to start the Scheduled job?

是的,理论上您可以(您可以在此处看到一个简单的示例),但是我不确定它是否适合您的用例(如果涉及应用服务器)-在正在运行的shell进程之外调用spring shell命令更为复杂.

Yes, theoretically you can (you can see a simple example here), but I am not sure it will fit your usecase if an application server is involved - invoking spring shell commands outside of the running shell process is more complex.

我会考虑将启动/停止功能作为REST API公开给Spring Scheduled Jobs.您仍然可以使用curl在命令行中执行它,并且可以围绕spring-security实现一些身份验证协议(如果不需要,则可以不执行).

I would look into exposing start/stop functionality to Spring Scheduled Jobs as a REST api. You can still execute it from command line using curl and you can implement some authentication protocol around spring-security (or not if it's not needed).

只需将启动/停止方法与控制器方法包装在一起,并将其公开为REST api.

Just wrap your start/stop methods with controller methods and expose those as REST api.

这篇关于从Linux Terminal启动Spring Scheduled作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆