项目启动时Quartz定时任务报错(已解决)

项目启动后,报如下错误


[cm] WARN [localhost-startStop-1] AbstractApplicationContext.refresh(487) | Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘mapScheduler’ defined in class path resource [application-quartz.xml]: Invocation of init method failed; nested exception is org.quartz.JobPersistenceException: Couldn’t retrieve trigger: No record found for selection of Trigger with key: ‘DEFAULT.syncTriggerBean’ and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = ‘mapScheduler’ AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ? [See nested exception: java.lang.IllegalStateException: No record found for selection of Trigger with key: ‘DEFAULT.syncTriggerBean’ and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = ‘mapScheduler’ AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ?]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
(省略)
Caused by: org.quartz.JobPersistenceException: Couldn’t retrieve trigger: No record found for selection of Trigger with key: ‘DEFAULT.syncTriggerBean’ and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = ‘mapScheduler’ AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ? [See nested exception: java.lang.IllegalStateException: No record found for selection of Trigger with key: ‘DEFAULT.syncTriggerBean’ and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = ‘mapScheduler’ AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ?]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1533)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$12.execute(JobStoreSupport.java:1522)
at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(JobStoreCMT.java:245)
(省略)
Caused by: java.lang.IllegalStateException: No record found for selection of Trigger with key: ‘DEFAULT.syncTriggerBean’ and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = ‘mapScheduler’ AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ?
at org.quartz.impl.jdbcjobstore.CronTriggerPersistenceDelegate.loadExtendedTriggerProperties(CronTriggerPersistenceDelegate.java:92)
at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectTrigger(StdJDBCDelegate.java:1819)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1531)
… 32 more


根据错误提示,解决方案如下

  1. 打开项目连接的数据库(我的是远程服务器上的数据库music);
  2. 打开数据表,找到错误提示中的QRTZ_CRON_TRIGGERS表;
    项目启动时Quartz定时任务报错(已解决)_第1张图片
    原表内容如下:
    QRTZ_CRON_TRIGGERS
    再看一遍核心错误提示:
    No record found for selection of Trigger with key: ‘DEFAULT.syncTriggerBean’ and statement: SELECT * FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME = ‘mapScheduler’ AND TRIGGER_NAME = ? AND TRIGGER_GROUP = ?
    结合表的内容可知,SCHED_NAME列少了名为mapScheduler、且TRIGGER_NAME为syncTriggerBean的项!
  3. 添加错误提示中的syncTriggerBean项(每个人定义的名称不同),其中,CRON_EXPRESSION为自定义的定时周期,和项目中定义的一致即可。
    QRTZ_CRON_TRIGGERS
  4. 重启项目。

你可能感兴趣的:(Java,Quartz,QRTZ_CRON_TRIGG,Tomcat,MySQL,Java)