The six fields in order
A Spring cron expression is six space-separated fields:
- second — 0-59
- minute — 0-59
- hour — 0-23 (24-hour clock)
- day-of-month — 1-31
- month — 1-12 or JAN-DEC
- day-of-week — 0-7 (0 and 7 are Sunday) or MON-SUN
@Scheduled(cron = "0 0 9 * * MON-FRI") // │ │ │ │ │ └── 09:00 on Monday to Friday // │ │ │ │ └──── every month // │ │ │ └────── every day of the month // │ │ └──────── 09:00 (24-hour clock) // └────────── minute 0 // ────────────── second 0
What each field accepts
Every numeric field accepts a single value ("5"), a range ("9-17"), a list ("1,15"), a wildcard ("*") and a step ("*/5" or "0-30/10").
A step without an asterisk starts at the value before the slash: "5/10" in the minute field means 5, 15, 25, 35, 45 and 55.
Letter-based syntax is case-insensitive, because Spring uppercases the expression before reading it. "MON-FRI", "mon-fri" and "Mon-Fri" are the same schedule, and so are "0 0 0 LW * *", "0 0 0 lw * *" and "0 0 0 Lw * *". Macros work the same way: @daily, @DAILY and @Daily all mean midnight every day.
0 0/30 8-10 * * * // every half hour between 08:00 and 10:59
Day-of-month specials
Spring supports the Quartz-style day constructs, which is what makes expressions such as "0 0 0 L * *" possible.
- L — the last day of the month
- L-<n> — n days before the end of the month, e.g. L-3
- LW — the last weekday (Monday-Friday) of the month
- <n>W — the weekday nearest day n, never crossing a month boundary
- ? — "no specific value"; Spring treats it like *
Day-of-week specials
In day-of-week, L and # describe an occurrence inside the current month.
- <dow>L — the last Monday/Friday/... of the month, e.g. 5L
- <dow>#<n> — the nth occurrence of that weekday, e.g. MON#1
0 0 0 ? * MON#1 // first Monday 0 0 0 * * 5L // last Friday
Both day fields must match
When day-of-month and day-of-week are both restricted, Spring requires a date to satisfy both of them — it is a logical AND, not the OR used by Unix cron. That is why Quartz-style expressions put ? in the unused field.
If you write "0 0 0 1 * MON", the job only runs on dates that are both the first of the month and a Monday.
Macros
Spring also accepts the usual cron macros, which expand to six-field expressions.
- @yearly / @annually → 0 0 0 1 1 *
- @monthly → 0 0 0 1 * *
- @weekly → 0 0 0 * * 0
- @daily / @midnight → 0 0 0 * * *
- @hourly → 0 0 * * * *