Spring Cron
Spring Framework's `@Scheduled` cron — 6 fields (with seconds), no `L`/`W`/`#`, and 0-indexed day-of-week like Unix.
Overview
Spring's `CronExpression` parser (used by `@Scheduled(cron = …)`) is a Quartz-inspired 6-field format, but it intentionally drops the year field and the `L`, `W`, `#`, and `?` tokens that Quartz supports.
Crucially, Spring uses Unix-style day-of-week numbering (0=Sun … 6=Sat) — not Quartz's 1=Sun convention. If you're porting Quartz expressions to Spring, the DOW values almost always need adjusting.
Field Structure
Field Order6 fields: second minute hour day-of-month month day-of-week
Day-of-Week0 or 7 = Sunday, 1=Monday, …, 6=Saturday.
Special Characters
| Token | Meaning |
|---|---|
| * | Any value. |
| , | List. |
| - | Range. |
| / | Step. |
Aliases
- `@yearly`, `@annually`, `@monthly`, `@weekly`, `@daily`, `@midnight`, `@hourly` (since Spring 5.3).
Comparison vs. Unix Cron
| Feature | Spring Cron | Unix Cron |
|---|---|---|
| Field count | 6 (seconds first) | 5 |
| Seconds field | Yes | No |
| Step syntax | Yes | Limited |
| Named months/days | Yes | No |
| Aliases | Yes (Spring 5.3+) | No |
| DOW numbering | 0=Sun … 6=Sat (like Unix) | 0=Sun … 6=Sat |
| `L`, `W`, `#` | No (not supported) | No |
| Year field | No | No |
Examples
Gotchas & Pitfalls
- ⚠Don't reuse Quartz expressions verbatim — DOW numbering differs (Quartz Sun=1, Spring Sun=0) and Spring rejects `?`, `L`, `W`, `#`.
- ⚠Pre-Spring-5.3 expressions used a different parser; check the migration notes if you're upgrading from Spring Boot 2.x.
- ⚠Spring's `@Scheduled(zone = …)` lets you pin a timezone per task — without it the JVM default applies.