如何编写cron表达式以便在每个月的25号早上9点开始触发一个函数?
当我执行此代码时,
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class PayrollSchedulerImpl implements PayrollScheduler{
@Scheduled(cron="0 9 25 1 * ?")
public void calculateSalaryScheduled()
{
calculateSalary();
}
public void calculateSalary()
{
/* */
}
}
我收到了错误,
java.lang.StackOverflowError
sun.util.calendar.ZoneInfo.getOffsets(Unknown Source)
sun.util.calendar.ZoneInfo.getOffsets(Unknown Source)
java.util.GregorianCalendar.computeFields(Unknown Source)
java.util.GregorianCalendar.computeTime(Unknown Source)
java.util.Calendar.updateTime(Unknown Source)
java.util.Calendar.complete(Unknown Source)
java.util.Calendar.get(Unknown Source)
org.springframework.scheduling.support.CronSequenceGenerator.doNext(CronSequenceGenerator.java:130)
答案 0 :(得分:20)
@Scheduled(cron="0 9 25 1 * ?")
这只是1月1日,时间无效,你需要这个:
@Scheduled(cron="0 0 9 25 * ?")
答案 1 :(得分:0)
每月 25 日触发的玉米。
@Scheduled(cron = "0 0 9 25 * ?")
使用此链接验证表达式
https://www.freeformatter.com/cron-expression-generator-quartz.html