Spring Quartz *.QRTZ_LOCKS' doesn't exist
ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Table 'zp60v1_db.QRTZ_LOCKS' doesn't exist [See nested exception: com.MySQL.jdbc.exceptions.MySQLSyntaxErrorException: Table 'zp60v1_db.QRTZ_LOCKS' doesn't exist]]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean
....
开发环境:
JDK 1.6
GWT 2.0
SmartGwt pro 2.0
hibernate 3.2
Spring 2.5
applicationContext.xml:
- <beans default-autowire=”autodetect”> <!–autowire is the cause of exception–>
- <bean id=”dataSource” class=”org.apache.commons.dbcp.BasicDataSource”>
- ……
- </bean>
- <bean id=”sessionFactory” class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
- ……
- </bean>
- …….
- <bean id=”cronReportTrigger” class=”org.springframework.scheduling.quartz.CronTriggerBean”>
- ……
- </bean>
- <bean id=”schedulerFactoryBean” class=”org.springframework.scheduling.quartz.SchedulerFactoryBean”>
- <property name=”triggers”>
- <list>
- <ref bean=”cronReportTrigger”/>
- </list>
- </property>
- </bean>
- </beans>
为了定时执行一项任务,设置了Quartz , 但是运行后异常" Failure obtaining db row lock: Table ‘hibernate.qrtz_locks’ doesn’t exist“,相信你肯定会感到困惑,甚至也许会奇怪为什么 SchedulerFactoryBean 和数据持久层有关。
原因:
事实上,这个异常是由于 Spring 的 autowire 属性引起的,SchedulerFactoryBean 类含有方法 : setDataSource. 因为autowire 属性使用了 autodetect , 并且也设置了 datasource 在项目中, spring 容器就自动将 dataSource 注入到SchedulerFactoryBean, 而SchedulerFactoryBean将从 dataSource 中查找计划任务。 但 dataSource 中并没有任务,因此抛出了异常。
幸运的是,当你知道了根本原因,就知道如何避免了。
解决方法:
不论 spring 的 default-autowire 设置为"autodetect " 还是 "byName" ,都会出现 *.QRTZ_LOCKS' doesn't exist
方法一: 不使用 default-autowire 属性;
方法二: 在不改变 spring default-autowire 属性的前提下, 给 SchedulerFactoryBean 设置 autowire="no"。
- <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="no">
- <property name="triggers">
- <list>
- <ref bean="simpleTriggerBean" />
- </list>
- </property>
- </bean>
- 原理:
<bean id="scheduler" lazy-init="false"
此bean会试图访问数据库获取quartz的一些管理表信息,自然访问数据库时需要注入dataSource bean,当缺省autowire为no,则没有dataSource bean被注入,quartz会认为项目没连数据库,会BYPASS这个访问管理表的功能.
当你配置了default-autowire=byName时,dataSource bean被自动注入,这时quartz认为项目既然能连到数据库,就想当然的认为对应的那些表一定存在,没找到时就出异常.
- 解决办法:
1.去掉default-autowire=byName即可
此法简单,但往往很难决定,因为缺省,谁也不会傻乎乎的显示配这么一条,配了它一定是有用到它的地方.你愿不愿意牺牲这部分byName注入的功能?
2.在库中建对应的表
此法不可取,因为非常麻烦,要建很多表
CREATE TABLE QRTZ_LOCKS
CREATE TABLE QRTZ_JOB_DETAILS
CREATE TABLE QRTZ_TRIGGERS
CREATE TABLE QRTZ_FIRED_TRIGGERS
CREATE TABLE QRTZ_JOB_LISTENERS
少一张,spring都报异常, 这是为大型调度功能准备的.你要有上百个任务,可能需要它.
3.bean里直接关掉autowired
推荐此法
| <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName" > |
| <bean id="scheduler" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> |
Spring Quartz *.QRTZ_LOCKS' doesn't exist的更多相关文章
- spring quartz分布式任务计划
spring quartz分布式任务计划 环境: 通过maven管理的spring mvc工程,且已经成功连接数据库. 数据库表结构 /*Table structure for table `qrtz ...
- Spring+quartz 实现定时任务job集群配置
为什么要有集群定时任务? 因为如果多server都触发相同任务,又同时执行,那在99%的场景都是不适合的.比如银行每晚24:00都要汇总营业额.像下面3台server同时进行汇总,最终计算结果可能是真 ...
- Spring+quartz 实现定时任务job集群配置【原】
为什么要有集群定时任务? 因为如果多server都触发相同任务,又同时执行,那在99%的场景都是不适合的.比如银行每晚24:00都要汇总营业额.像下面3台server同时进行汇总,最终计算结果可能是真 ...
- 【示例】Spring Quartz入门
JAVA 针对定时任务,有 Timer,Scheduler, Quartz 等几种实现方式,其中最常用的应该就是 Quartz 了. 一. Quartz的基本概念 在开始之前,我们必须了解以下的几个基 ...
- 基于spring+quartz的分布式定时任务框架
问题背景 我公司是一个快速发展的创业公司,目前有200人,主要业务是旅游和酒店相关的,应用迭代更新周期比较快,因此,开发人员花费了更多的时间去更=跟上迭代的步伐,而缺乏了对整个系统的把控 没有集群之前 ...
- Spring Quartz
Spring Quartz Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz,下面就看看在Spring中怎样配置Quartz: 首先我们来写一个被调度的类: pac ...
- [Spring] - Quartz定时任务 - Annotation
Spring + Quartz可以使用annoation方式: 1.AppJob类: package com.my.quartz.testquartz1; import org.springframe ...
- atititt.java定时任务框架选型Spring Quartz 注解总结
atititt.java定时任务框架选型Spring Quartz 总结 1. .Spring Quartz (ati recomm) 1 2. Spring Quartz具体配置 2 2.1. 增 ...
- 解决Spring+Quartz无法自动注入bean问题
问题 我们有时需要执行一些定时任务(如数据批处理),比较常用的技术框架有Spring + Quartz中.无奈此方式有个问题:Spring Bean无法自动注入. 环境:Spring3.2.2 + Q ...
随机推荐
- Jupyter 环境配置
1. 找到python文件目录, 用管理员身份打开powershell python -m pip install jupyter 2. Jupyter notebook
- 德国生活tips
提要: 在德国生活也近7个月的时间了,简单给准备来德国留学,生活或者是旅游的人写一些小tips.想到什么就写什么咯. (1)德国交通篇 在德国,交通是第一要点,一般大家都会看到城市里有Straßenb ...
- hdfs shell命令及java客户端编写
一. hdfs shell命令 可以通过hadoop fs 查看所有的shell命令及其用法. 传文件到hdfs: hadoop fs -put /home/koushengrui/Downloads ...
- VIM操作手札
查看帮助手册 [Vim 中文帮助文档] 常用命令及说明 在命令模式下编辑 命令 说明 Ctrl+u 向文件首翻半屏 Ctrl+d 向文件尾翻半屏 Ctrl+f 向文件尾翻一屏 Ctrl+b 向文件首翻 ...
- sqoop导出数据
export是HDFS里的文件导出到RDBMS的工具,不能从hive.hbase导出数据,且HDFS文件只能是文本格式.如果要把hive表数据导出到RDBMS,可以先把hive表通过查询写入到一个临时 ...
- CentOS 7 Linux 卸载/安装 Mariadb MySQL mysql 5.7
[root@localhost mysql]# ls mysql-community-client--.el7.x86_64.rpm mysql-community-embedded-compat-- ...
- windows下自动更改IP的小工具(bat批处理文件)
每次上线,都要先上灰度环境再上到正式环境.在上到灰度环境时,访问灰度环境通过自动获取IP和更改指定dns来实现.具体如何实现,大家可自行百度. 新建一个文本文档,将其后缀改为bat,打开该文件,拷贝一 ...
- 利用COM组件实现对WORD书签处写入值
using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Interop.Wo ...
- JAVA ------ 大牛
李学凯 :http://blog.csdn.net/qq_27093465/article/details/51750535 码农场:http://www.hankcs.com/program/ 徐刘 ...
- 高仿饿了么mock本地数据
未使用router新版webpack.dev.conf.js配置本地数据访问:// 引入express 模块 const express = require('express') // 创建expre ...