Spring Cron Scheduler "Disable Template"

My application loads some cron templates from a properties file. Im using annotation @Scheduledas follows:

@Scheduled(cron = "${config.cronExpression:0 0 11,23 * * *}")

Now I want to disable some tasks, and the easiest solution would be to introduce a cron template that will never work. To do this, I thought about using a cron expression that only runs on a specific day in the past. But unfortunately, Spring cron expressions do not allow adding a year or date in the past.

Is there any pattern that will never work?

+7
source share
4 answers

Javadocs, Spring 5.1.0 @Scheduled "-" cron cron.

"-" cron, , $ {...}.

+5

cron, , cron 2099

59 59 23 31 12 ? 2099

. , , . 29 , .

0 0 0 29 2 ?
+1

If you are stuck before Spring 5.1.0 (SpringBoot <2.1), the only option might be to disable bean / service from the @Scheduledmethod @Scheduled, for example, using an @ConditionalOnProperty("my.scheduleproperty.active")annotation and not setting the property (or setting it to false)

0
source

While this is not possible, check the URL https://jira.spring.io/browse/SPR-10376 .

-1
source

All Articles