quartz每月最后一天执行 报错 定时59 59 23 L * ?

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.scheduling.config.CronTask]: Constructor threw exception; nested exception is java.lang.NumberFormatException: For input string: "L"
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
... 24 more
我看文档上写的 第四个参数 “日” 是可以写成L 的 为什么会给我报错呢

第1个回答  2018-11-26
因为spring的@Scheduled注解的cron不支持L,W,C这些字符
源码private void parse(String expression) throws IllegalArgumentException { String[] fields = StringUtils.tokenizeToStringArray(expression, " "); if (fields.length != 6) { throw new IllegalArgumentException(String.format( "Cron expression must consist of 6 fields (found %d in \"%s\")", fields.length, expression)); } setNumberHits(this.seconds, fields[0], 0, 60); setNumberHits(this.minutes, fields[1], 0, 60); setNumberHits(this.hours, fields[2], 0, 24); setDaysOfMonth(this.daysOfMonth, fields[3]); setMonths(this.months, fields[4]); setDays(this.daysOfWeek, replaceOrdinals(fields[5], "SUN,MON,TUE,WED,THU,FRI,SAT"), 8); if (this.daysOfWeek.get(7)) { // Sunday can be represented as 0 or 7 this.daysOfWeek.set(0); this.daysOfWeek.clear(7); } }
第2个回答  2014-12-24

7个参数都设置了:

59 59 23 L * * *

追问

试过了 还是会报错 我用的是quartz1.7.3 是不是版本问题?

追答

恩,可能是的,不如这样写:

0 0 0 1 * ?

每月1号零点执行,相当于月末了,不使用“L”应该没这个错了。

本回答被网友采纳
第3个回答  2014-12-24
多空拉锯哦i饿啊追问

饿就去吃饭去

相似回答