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">原理