Spring error Something that is not a number
For input string: "?" '?' in cron expression "0 ? * * * *"
java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': For input string: "?" '?' in cron expression "0 ? * * * *"java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': For input string: "H" 'H' in cron expression "H 0 9 * * *"java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': For input string: "l" 'l' in cron expression "0 0 9 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
After expanding names such as MON and JAN and the special forms L, W and #, Spring reads every remaining item as a whole number. When that fails, Java’s NumberFormatException text comes straight through, quoting the piece it could not read.
The usual causes are ? outside the two day fields, Jenkins’ H, a lower-case l or w in day of month (names are case-insensitive, those letters are not), L in an hour or minute field, and W in day of week.
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 * * * * *Every minute.
Every minute.
?only means “any” in day of month and day of week; use*elsewhere. -
Use0 0 9 ? * *At 09:00.
Every day at 09:00. Month cannot be
?. -
Use0 0 9 * * *At 09:00.
His Jenkins’ hash syntax. Pick a fixed second instead. -
Use0 0 9 L * *At 09:00, on the last day of the month.
The last day of the month.
Lmust be a capital. -
Use0 0 9 * * FRIAt 09:00, on Fridays.
Wbelongs in day of month, as in15W. In day of week, name the day.
Questions
- Can I use
?in Spring cron? - Yes, in day of month and day of week, where it means the same as
*. Spring does not require it, unlike Quartz, so0 0 9 * * MONis fine. - Are Spring cron expressions case-sensitive?
- Month and day names are not:
mon-friworks. TheLandWin day of month must be capitals.
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
- No day-of-week before 'L' in 'L' in cron expression "0 0 0 * * L"Spring:
Lalone in day of week