I have an app that uses the \"task:scheduler\" and \"task:scheduled-tasks\" elements (the latter containing \"task:scheduled\" elements). This is all working fine.
With @Scheduled
based configuration the approach from Tobias M’s answer does not work out-of-the-box.
Instead of autowiring a ScheduledTaskRegistrar
instance (which is not available for annotation based configuration), you can instead autowire a ScheduledTaskHolder
which only has a getScheduledTasks()
method.
Background:
The ScheduledAnnotationBeanPostProcessor
used to manage @Scheduled
tasks has an internal ScheduledTaskRegistrar
that’s not available as a bean. It does implement ScheduledTaskHolder
, though.