-
Notifications
You must be signed in to change notification settings - Fork 38k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide support for disabling cron-based scheduled jobs registered via SchedulingConfigurer #23568
Comments
This should be easy enough to support, and I'll take a look into it in detail. public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.addCronTask(this::ticker2, this.ticker2Cron);
} In the interim, you can effectively replace the above with the following for a workaround. public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
if (!Scheduled.CRON_DISABLED.equals(this.ticker2Cron)) {
taskRegistrar.addCronTask(this::ticker2, this.ticker2Cron);
}
} |
This has been addressed for Spring Framework 5.2 in d689ef8. @jhoeller and @snicoll, the |
Thanks for the quick resolution @sbrannen! 👍 |
This commit removes the duplicated CRON_DISABLED constant value from @Scheuled and simply refers to the ScheduledTaskRegistrar.CRON_DISABLED constant. This avoids a potential package cycle by ensuring that the `annotation` package depends on the `config` package but not the other way around. See gh-23568
Support for special cron value of
-
(as defined inScheduled#CRON_DISABLED
) was introduced in #21397 however this is limited to use of@Scheduled
.For scheduled jobs registered via
SchedulingConfigurer
this is not supported which means there's no way to disable scheduled job by supplying the cron value.This can be demonstrated using a simple Spring Boot based sample application:
This works equally well for all cases, except for
-
which will blow up withjava.lang.IllegalArgumentException: Cron expression must consist of 6 fields (found 1 in "-")
when supplied forticker2.cron
.The text was updated successfully, but these errors were encountered: