Spring中集成Quartz时遭遇Failure obtaining db row lock异常

今天在一个新的项目中用Spring集成Quartz来进行任务调度,和以往一样,配置好JobDetail、Trigger、SchedulerFactoryBean启动,却遭遇到如下异常信息:

[java] view plain copy print ?
  1. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sfb' defined in URL [jar:file:/.../xxx-biz-service.jar!/bean/spring-task.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: ORA-00942: table or view does not exist
  2. [See nested exception: java.sql.SQLException: ORA-00942: table or view does not exist
  3. ]]
  4. Caused by:
  5. org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: ORA-00942: table or view does not exist
  6. [See nested exception: java.sql.SQLException: ORA-00942: table or view does not exist
  7. ]]
  8. at org.quartz.impl.jdbcjobstore.JobStoreSupport.initialize(JobStoreSupport.java:493)
  9. at org.quartz.impl.jdbcjobstore.JobStoreCMT.initialize(JobStoreCMT.java:144)
  10. at org.springframework.scheduling.quartz.LocalDataSourceJobStore.initialize(LocalDataSourceJobStore.java:133)
  11. at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1010)
  12. at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1152)
  13. at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:668)
  14. at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:568)
  15. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1057)
  16. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1024)
  17. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
  18. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
  19. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
  20. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
  21. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
  22. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
  23. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
  24. at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:92)
  25. at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:77)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sfb' defined in URL [jar:file:/.../xxx-biz-service.jar!/bean/spring-task.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: ORA-00942: table or view does not exist [See nested exception: java.sql.SQLException: ORA-00942: table or view does not exist ]] Caused by: org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: ORA-00942: table or view does not exist [See nested exception: java.sql.SQLException: ORA-00942: table or view does not exist ]] at org.quartz.impl.jdbcjobstore.JobStoreSupport.initialize(JobStoreSupport.java:493) at org.quartz.impl.jdbcjobstore.JobStoreCMT.initialize(JobStoreCMT.java:144) at org.springframework.scheduling.quartz.LocalDataSourceJobStore.initialize(LocalDataSourceJobStore.java:133) at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1010) at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1152) at org.springframework.scheduling.quartz.SchedulerFactoryBean.createScheduler(SchedulerFactoryBean.java:668) at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:568) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1057) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1024) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:92) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:77)

 

这是一个很奇怪的错误,从打印的异常信息可以看出:quartz试图将任务执行情况持久化到数据库中,一般是在集群环境中使用的一种同步任务的方法,保证某一时刻集群中只有一台机器执行定时任务。
但是,令我奇怪的是,第一,我没有配置quartz的数据源信息;第二,我也没有配置quartz的cluster,quartz应该是在内存中维护任务列表才对。因为我们根本就没有自定义quartz.properties

从日志上看,这的确是Quartz抛出来的异常,而且就是SchedulerFactoryBean.createScheduler时出现了问题;直接查看SchedulerFactoryBean的源码,惊奇的发现了dataSource这个属性!!而且在setDataSource方法注释里面说明了该属性将覆盖quartz.properties文件配置的datasource;看到这个属性就一切都明了了,原来又是Spring的自动注入惹的祸!前段时间刚刚遭遇过同类事件,具体可参见《网店版重生系列:都是Spring配置中自动注入惹的祸》;

一般情况下我们数据源的beanId都是dataSource,所以在Spring自动注入的情况下,Spring再一次自作聪明了一把!解决办法有二:其一,取消quartz任务相关配置所在bean的自动注入,注意:无需将所有Spring配置文件中的自动注入都去西欧啊;其二:将系统数据源datasource这个beanId进行改名;

 

转自:http://blog.csdn.net/sfdev/article/details/4360011

你可能感兴趣的:(Spring)