检查计划任务Spring

时间:2017-08-25 08:44:41

标签: xml spring scheduled-tasks

需要检查xml文件中的计划任务:

<task:scheduled-tasks>
  <task:scheduled ref="task" method="execute"/>
</task:scheduled-tasks>

但他们可以被注释掉:

<--<task:scheduled-tasks>
  <task:scheduled ref="task" method="execute"/>
</task:scheduled-tasks>-->

我正在尝试在控制器中执行此操作:

@Autowired
ScheduledTaskRegistrar scheduledTaskRegistrar;

... // some code

public List<Task> getScheduledTasks() {
  List<Task> allTasks = new ArrayList<>();
  allTasks.addAll(scheduledTaskRegistrar.getFixedDelayTaskList());
  allTasks.addAll(scheduledTaskRegistrar.getFixedRateTaskList());
  allTasks.addAll(scheduledTaskRegistrar.getCronTaskList());
  allTasks.addAll(scheduledTaskRegistrar.getTriggerTaskList());
  return allTasks;
}

如果任务在xml文件中被注释掉,那么我会收到以下错误:

No qualifying bean of type [org.springframework.scheduling.config.ContextLifecycleScheduledTaskRegistrar] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.  

0 个答案:

没有答案