spring quartz 常见的"Table 'database.qrtz_locks' doesn't exist异常"

原因:出现此异常,通常是因为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认为项目既然能连到数据库,就想当然的认为对应的那些表一定存在,没找到时就出异常

解决办法

<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 常见的"Table 'database.qrtz_locks' doesn't exist异常")