spring quartz 常见的"Table 'database.qrtz_locks' doesn't exist异常"spring
缘由:出现此异常,一般是由于spring配了 <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" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 此bean会试图访问数据库获取quartz的一些管理表信息,天然访问数据库时须要注入dataSource bean,当缺省autowire为no,则没有dataSource bean被注入,quartz会认为项目没连数据库,会BYPASS这个访问管理表的功能. 当你配置了default-autowire=byName时,dataSource bean被自动注入,这时quartz认为项目既然能连到数据库,就想固然的认为对应的那些表必定存在,没找到时就出异常.xml
解决办法:get
1.去掉default-autowire=byName便可 此法简单,但每每很难决定,由于缺省,谁也不会傻乎乎的显示配这么一条,配了它必定是有用到它的地方.你愿不肯意牺牲这部分byName注入的功能?it
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都报异常, 这是为大型调度功能准备的.你要有上百个任务,可能须要它.io
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 >class
<bean id="scheduler" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">原理