Cron Atlas

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.

  1. Rejected0 0 0 * * LNo day-of-week before 'L' in 'L' in cron expression "0 0 0 * * L"
    Use
    0 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: L belongs in day of month.

  2. Rejected0 0 9 * * LNo day-of-week before 'L' in 'L' in cron expression "0 0 9 * * L"
    Use both
    0 0 9 * * SATLAt 09:00, on the last Saturday of the month.
    and
    0 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 5L or FRIL in day of week: 0 0 9 * * FRIL. Spring counts Monday as 1, so 5 is Friday; in Quartz it would be 6L.
Is 0 0 0 L * * the last day of the month in Spring?
Yes. In day of month, L on its own is the last day, and L-3 is three days before it.

Other Spring errors

Reference