It's my first time using the annotation @Scheduled
and i need it to repeat the code evry hour from 8to20 from monday to friday, so i used one of the multiple cron generator online and this is what came out :
@Scheduled(cron = "0 0 8-20 ? * MON-FRI *")
public void deleteExpiredSlots() {
//my code here
}
i get this error Cron expression must consist of 6 fields (found 7 in "0 0 8-20 ? * MON-FRI *")
I removed the ?
and the error changed to Encountered invalid @Scheduled method 'deleteExpiredSlots': For input string: "MON" 'MON-FRI' in cron expression "0 0 8-20 * MON-FRI *"
Someone knows what's the problem and possibly how to solve it?
CodePudding user response:
The seven parameter CRON expression is only supported as of Spring 5.3. Prior to this, you should use this 6 parameter version:
@Scheduled(cron = "0 0 8-20 * * MON-FRI")
public void deleteExpiredSlots() {
// your code here
}
The above will fire at the top of the hour from 8am to 8pm inclusive, on weekdays.