Quartz SchedulerFactoryBean异常–Spring自动装配惹的祸

Quartz SchedulerFactoryBean异常–Spring自动装配惹的祸QuartzSchedulerFactoryBean异常–Spring自动装配惹的祸2011-02-1220:45:02|分类:Spring|标签:quartzdatasourcebeanspringproperty|字号订阅Spring的配置文件,启用了自动装配模式:<beansdefault-autowire=”byName”>…

大家好,又见面了,我是你们的朋友全栈君。

Quartz SchedulerFactoryBean异常–Spring自动装配惹的祸  

2011-02-12 20:45:02|  分类: Spring |  标签:quartz  datasource  bean  spring  property   |字号 订阅
Spring的配置文件,启用了自动装配模式:
<beans default-autowire=”byName”>

<bean id=”dataSource” class=”…”></bean>

<bean class=”org.springframework.scheduling.quartz.SchedulerFactoryBean” lazy-init=”false”>
  <property name=”triggers”>
   <list><ref bean=”clearLogsTrigger” /></list>
  </property>
 </bean>

  …

</beans>

则此时会产生如下错误:

Error creating bean with name ‘org.springframework.scheduling.quartz.SchedulerFactoryBean#0’ defined in file [E:\workspace\eis_oracle2\web\WEB-INF\classes\conf\spring\eisSystemScheduleContext.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

原因:其实这都是Spring的自动装配惹得祸,当存在dataSource的bean,在初始化SchedulerFactoryBean时就自动装配该dataSource属性,此时就启用了jobstore的LocalDataSourceJobStore模式使用数据库来维持状态,quartz的jobstore会从数据库中查询任务。quartz使用数据库进行job状态的维护,但是在数据库中没有找到相应的table,从而无法正常初始化scheduler 。

解决:屏蔽掉自动装配,如下:

<bean class=”org.springframework.scheduling.quartz.SchedulerFactoryBean” autowire=”false”>
  <property name=”triggers”>
   <list><ref bean=”clearLogsTrigger” /></list>
  </property>
 </bean>

另:启用jobstore的RAMJobStore(内存存储的)模式,配置如下:

<bean class=”org.springframework.scheduling.quartz.SchedulerFactoryBean” autowire=”false”>
  <property name=”triggers”>
   <list> <ref bean=”clearLogsTrigger” /></list>
  </property>
  <property name=”quartzProperties”>
   <props>
    <prop key=”org.quartz.jobStore.class”>org.quartz.simpl.RAMJobStore</prop>
   </props>
  </property>
 </bean>

当设置了dataSource属性,jobStore属性设置将无效,原因是:

if (this.dataSource != null) {     
    mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());   
}  

详细介绍请参见 SchedulerFactoryBean 方法 setDataSource(DataSource)的javadoc: 
Set the default DataSource to be used by the Scheduler. If set, this will override corresponding settings in Quartz properties. 

Note: If this is set, the Quartz settings should not define a job store “dataSource” to avoid meaningless double configuration. 

A Spring-specific subclass of Quartz’ JobStoreCMT will be used. It is therefore strongly recommended to perform all operations on the Scheduler within Spring-managed (or plain JTA) transactions. Else, database locking will not properly work and might even break (e.g. if trying to obtain a lock on Oracle without a transaction). 

Supports both transactional and non-transactional DataSource access. With a non-XA DataSource and local Spring transactions, a single DataSource argument is sufficient. In case of an XA DataSource and global JTA transactions, SchedulerFactoryBean’s “nonTransactionalDataSource” property should be set, passing in a non-XA DataSource that will not participate in global transactions.

 

补单系统源码

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/142461.html原文链接:https://javaforall.net

(0)
上一篇 2022年5月23日 下午6:40
下一篇 2022年5月23日 下午6:40


相关推荐

  • C语言实现哈希查找

    C语言实现哈希查找哈希查找的主要过程是如何建立以哈希表及如何解决元素位置占用的问题 nbsp nbsp nbsp nbsp 建立哈希表 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 首先需要初始化哈希表 并且确实哈希表的长度 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 并且根据 数据 哈希表长度 计算出数据在哈希表中的位置 nbsp nbsp nbsp nbsp nbsp 解决元素占位问题 nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 如果在计算出这个数据在哈希表中的位置 但是这个位置上有元素 则将这个位置 将这个数据

    2026年3月17日
    3
  • SpringBoot自动装配原理「建议收藏」

    SpringBoot自动装配原理「建议收藏」SpringBoot项目无需各种配置文件,一个main方法,就能把项目启动起来。那么我们看看SpringBoot是如何进行自动配置和启动的。SpringBoot通过main方法启动SpringApplication类的静态方法run()来启动项目。根据注释的意思,run方法从一个使用了默认配置的指定资源启动一个SpringApplication并返回ApplicationContext对象,这个默认配置如何指定呢?这个默认配置来源于@SpringBootApplication注解,这个注解是个复

    2022年8月20日
    6
  • OLAP基础

    OLAP基础基本概念 nbsp 联机实时分析 OnlineAnalyt OLAP o l p 技术是快速响应多维分 Multidimensi MDA 的一种解决方案 nbsp 首先 解释下什么是多维分析 多维分析是一种数据分析过程 在此过程中 将数据分成两类 维度 dimensions 和度量 metrics measurements 维

    2026年3月17日
    2
  • 台式机通过网线连接笔记本上网「建议收藏」

    台式机通过网线连接笔记本上网「建议收藏」2019独角兽企业重金招聘Python工程师标准>>>…

    2022年6月26日
    45
  • [RPI]树莓派监控温度及报警关机保护「建议收藏」

    最近把树莓派用作了Aria2下载机+无线路由,24小时不间断工作,生怕机子有时会过热烧坏,所以写了个脚本做温度记录,以及在温度过高时能自动关机保护。下面直接上Shell脚本(/data/temperature.sh):#!/bin/sh#高温阈值hot_temp=80.0#低温阈值cold_temp=-70.0#过热预警连续出现次数hot_cnt=0#过冷预警连…

    2022年4月15日
    70
  • MySQL自定义函数实例「建议收藏」

    MySQL自定义函数实例「建议收藏」关于MySQL函数的基本内容,网上有很多的资料,仅在此整理一些有价值的sql实例,以方便自己阅读,见例子便知内容。1.求两点之间的距离?DELIMITER//CREATEFUNCTIONdistance_fn(x1DOUBLE,y1DOUBLE,x2DOUBLE,y2DOUBLE)RETURNSDOUBLEBEGINSET@distanc…

    2025年10月2日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号