Silvio Araujo
Silvio Araujo

Reputation: 71

Can we make a @Scheduled execution on Spring, mixed with cron parameter, forcing a first execution at boot time?

I made many searches over internet about an option mentioned by Baeldung here, but I can't find any example. I would like to use something like this:

@Scheduled(cron="@reboot")
@Scheduled(cron="0 0 5 * * *")
public void somethingToDoOnRebootTime() {
  // code here, to run every day at 5a.m., AND at boot first time... 
}

But it didn't work, 'cause "@reboot" is not a valid cron expression... I tried to use this "@reboot" as a normal annotation to the method, but it didn't exists too...

Someone can help me? Is the article on Baeldung wrong?

Upvotes: 0

Views: 1007

Answers (1)

Silvio Araujo
Silvio Araujo

Reputation: 71

Based on @M.Deinum comment... I used ApplicationListener but with ApplicationReadyEvent! So, my example becames:

@EventListener(ApplicationReadyEvent.class)
@Scheduled(cron="0 0 5 * * *")
public void somethingToDoOnRebootTime() {
  // code here, to run every day at 5a.m., AND at boot first time... 
}

Upvotes: 2

Related Questions