https://jira.spring.io/browse/SPR-12748(免责声明:我报告了此问题,并为解决该问题提供了代码)。
// Warning there may be more than one ScheduledTaskRegistrar in your// application context. If this is the case you can autowire a list of // ScheduledTaskRegistrar instead.@Autowired private ScheduledTaskRegistrar scheduledTaskRegistrar; public List<Task> getScheduledTasks() { List<Task> result = new ArrayList<Task>(); result.addAll(this.scheduledTaskRegistrar.getTriggerTaskList()); result.addAll(this.scheduledTaskRegistrar.getCronTaskList()); result.addAll(this.scheduledTaskRegistrar.getFixedRateTaskList()); result.addAll(this.scheduledTaskRegistrar.getFixedDelayTaskList()); return result;}// You can this inspect the tasks, // so for example a cron task can be inspected like this:public List<CronTask> getScheduledCronTasks() { List<CronTask> cronTaskList = this.scheduledTaskRegistrar.getCronTaskList(); for (CronTask cronTask : cronTaskList) { System.out.println(cronTask.getexpression); } return cronTaskList;}
如果您使用的是XML中定义的ScheduledMethodRunnable:
<task:scheduled method="run" cron="0 0 12 * * ?" ref="MyObject" />
您可以访问基础目标对象:
ScheduledMethodRunnable scheduledMethodRunnable = (ScheduledMethodRunnable) task.getRunnable(); TargetClass target = (TargetClass) scheduledMethodRunnable.getTarget();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)