我有一种情况,我想从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作业
发布评论