问题
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?
For example can I use Spring Shell to start the Scheduled job?
回答1:
can I use Spring Shell to start the Scheduled job?
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.
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).
Just wrap your start/stop methods with controller methods and expose those as REST api.
来源:https://stackoverflow.com/questions/55622199/start-spring-scheduled-job-from-linux-terminal