简体   繁体   English

如何从UI调用Spring Scheduler

[英]How to call spring scheduler from UI

I have defined a spring scheduler and it works automatically based on the cron i gave but i would like to call the scheduler from UI so that this scheduler can be run whenever some one wants to run. 我已经定义了一个Spring Scheduler,它会根据我提供的Cron自动运行,但是我想从UI调用该Scheduler,以便可以在有人要运行时运行此Scheduler。

<bean id="schedulerToCall" class="validPackagename.schedulerToCallTask" />

I would like to call this spring bean in some controller manually. 我想在某些控制器中手动调用此spring bean。

how to call that ? 怎么称呼它?

Thanks 谢谢

for example your context config is like this: 例如,您的上下文配置是这样的:

<bean id="schedulerToCall" class="validPackagename.SchedulerToCallTask" />
<task:scheduled-tasks>
    <task:scheduled ref="schedulerToCall" method="runTaskMethod" cron="0 1 0 * * MON"/>
</task:scheduled-tasks>

In SchedulerToCallTask.java : SchedulerToCallTask.java

@Component
public class SchedulerToCallTask{

In the controller class you can just: 在控制器类中,您可以:

@Resource
SchedulerToCallTask schedulerToCallTask;

In the controller function you want to call this task: 在控制器功能中,您要调用此任务:

schedulerToCallTask.runTaskMethod();

If I understood your query correctly. 如果我正确理解您的查询。 since cron runs based on the cron parameters, you need to pass the current time in the cron parameter. 由于cron基于cron参数运行,因此您需要在cron参数中传递当前时间。 Also that cron parameters should be passed dynamically when the use want to run. 另外,当要运行使用时,应动态传递cron参数。

eg: 例如:

<task:scheduled ref="cronService" method="runCron" cron="* 0 0 * * ?"></task:scheduled>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM