Spring error L alone in day of week
No day-of-week before 'L' in 'L' in cron expression "0 0 0 * * L"
java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': No day-of-week before 'L' in 'L' in cron expression "0 0 0 * * L"Message produced by running the expression through org.springframework.scheduling.support.CronExpression from Spring Framework 7.0.10, the parser behind @Scheduled. 6.2.19 prints the same.
What it means
In day of week, Spring only accepts L after a day: 5L or FRIL is the last Friday of the month. On its own it is rejected, even though Spring’s reference documentation says a bare L in day of week stands for the last day of the week. Versions 7.0.10 and 6.2.19 both reject it with this message.
In Quartz a bare L in day of week means Saturday, so expressions copied from Quartz can hit this too.
Rejected expressions and their fixes
Each expression opens in the tester. The message under a rejected one is what Spring Framework 7.0.10 printed for it.
-
Use0 0 0 L * *At 00:00, on the last day of the month.
Midnight on the last day of the month, if that was the intent:
Lbelongs in day of month. -
Use both0 0 9 * * SATLAt 09:00, on the last Saturday of the month.and0 0 9 * * SATAt 09:00, on Saturdays.
The last Saturday of the month, or every Saturday, depending on what was meant.
Questions
- How do I schedule the last Friday of the month in Spring?
- Use
5LorFRILin day of week:0 0 9 * * FRIL. Spring counts Monday as 1, so5is Friday; in Quartz it would be6L. - Is
0 0 0 L * *the last day of the month in Spring? - Yes. In day of month,
Lon its own is the last day, andL-3is three days before it.
Other Spring errors
- Cron expression must consist of 6 fields (found 5 in "*/5 * * * *")Spring: Five or seven fields
- Minimum value must be less than maximum value '22-2' in cron expression "0 0 22-2 * * *"Spring: A range that runs backwards
- Invalid value for HourOfDay (valid values 0 - 23): 24 '24' in cron expression "0 0 24 * * *"Spring: A value outside the field
- For input string: "?" '?' in cron expression "0 ? * * * *"Spring: Something that is not a number