spring+quartz报错:Table 'XXXX.QRTZ_TRIGGERS' doesn't exist

Spring4.3.4 + quartz2.2.1配置到application.xml中

<properties>
    <spring.version>4.3.4.RELEASE</spring.version>
</properties>

<dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>2.2.1</version>
</dependency>

报错如下

Caused by: org.quartz.JobPersistenceException: Couldn't retrieve trigger: Table 'TEST.QRTZ_TRIGGERS' doesn't exist [See nested exception: 
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'BANKSTEELERP_OLD.QRTZ_TRIGGERS' doesn't exist]
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)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeWithoutLock(JobStoreSupport.java:3723)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1519)
at org.quartz.core.QuartzScheduler.getTrigger(QuartzScheduler.java:1530)
at org.quartz.impl.StdScheduler.getTrigger(StdScheduler.java:508)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:196)
... 59 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'TEST.QRTZ_TRIGGERS' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.Util.getInstance(Util.java:382)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2273)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:210)
at org.quartz.impl.jdbcjobstore.StdJDBCDelegate.selectTrigger(StdJDBCDelegate.java:1761)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.retrieveTrigger(JobStoreSupport.java:1531)
... 70 more

spring.xml:文件中:

<beans .... default-autowire="byName">

<!-- Execution timing task -->
<!-- The business object -->
<bean id="bizObject" class="com.gmq.quartz.utils.JobTask" />

<!-- Dispatch services -->
<bean id="jobDetail"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="bizObject" />
    <property name="targetMethod" value="doBiz" />
</bean>

<!-- quartz-2.x configuration triggers increased scheduling -->
<bean id="cronTrigger"
    class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
    <property name="jobDetail" ref="jobDetail" />
    <property name="cronExpression" value="0 */1 * * * ?" />
</bean>

<!-- Setting Scheduling -->
<bean name="startQuertz" lazy-init="false"
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="cronTrigger" />
        </list>
    </property>
</bean>

</beans>

  我的文件中的配置如上,报错如上。

经过调查:

<bean name="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

  加入autowire="no": 加上这句,不自动织入。

原因如下:

  在<Beans>中不能够设置default-autowire="byName"的属性,必须去掉,否则后台会报table or view does not exist错误,这就是autowire自动装配引起的。表示quartz会使用数据库记录job的状态而进行维护,但是这些日志表又不存在,从而引发错误。autowire自动装配会自动调用dataSource这个bean(hibernate配置的这个bean),但是数据库中又没有相应记录job的表,这就是报这个错误的原因

原文地址:https://www.cnblogs.com/jing99/p/7845016.html