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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 软件安全之动态链接库的使用 Libzplay 播放音乐「建议收藏」

    实验1动态链接库的使用实验说明Libzplay是遵循GPL协议的开源库,它集成了mp3、flac、ac3、aac、wav等多种音频格式的解码器和编码器,提供了面向C/C++、C#、Delphi等多种编程语言的接口,仅需3行代码(创建播放资源,打开文件,开始播放)便可实现音乐播放功能。实验目的本实验通过Libzplay提供的C语言接口,实现简单的音乐播放器,以此学习DLL的隐式和显式加载方式。实验原理课程第2讲基础知识实验环境Windows

    2022年4月17日
    69
  • 图解Golang的GC算法「建议收藏」

    图解Golang的GC算法「建议收藏」虽然Golang的GC自打一开始,就被人所诟病,但是经过这么多年的发展,Golang的GC已经改善了非常多,变得非常优秀了。以下是GolangGC算法的里程碑:v1.1STWv1.3MarkSTW,Sweep并行v1.5三色标记法v1.8hybridwritebarrier经典的GC算法有三种:引用计数(referencecounting)、标记-清扫(mar…

    2022年6月22日
    52
  • C++中fstream_在使用中

    C++中fstream_在使用中C++中fstream的使用

    2026年1月21日
    1
  • Laravel 7 新版本发布,新功能及更改

    Laravel 7 新版本发布,新功能及更改

    2022年2月15日
    43
  • LLDP报文格式

    LLDP报文格式前面已经知道了FloodlightController是通过从SW发送LLDP帧来获得链路信息的,链路层发现协议(L2)是通过在本地网络中广播LLDP报文来通告自己的设备信息,从而服务于拓扑计算,(wikipedia:LLDPinformationissentbydevicesfromeachoftheirinterfacesatafixedinterval,i

    2022年5月28日
    46
  • 《Java编程思想》总结

    《Java编程思想》总结语言实际上是帮助程序员更容易地操作计算机的工具,选择何种语言来编程,是Java还是C++,本质上相当于“选择腾讯视频还是优酷视频来观看电视节目(那么选择汇编语言就是选择了电视机)”。正如腾讯视频是腾讯公司的产品,Java是美国公司Sun的产品。希望读者能明白:语言只是工具。

    2022年7月9日
    23

发表回复

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

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