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


相关推荐

  • winformlistview用法_listview控件的用法

    winformlistview用法_listview控件的用法Winform中的ListView排序是一种常用的功能,下面是例子代码,放上来留个备份using System;using System.Windows.Forms;using System.Drawing;using System.Collections;namespace ListViewSortFormNamespace…{     public class ListViewSo

    2022年10月3日
  • linux下发送邮件[通俗易懂]

    linux下发送邮件[通俗易懂]先安装一个mailxyuminstallmailx配置:126邮箱为例,自己去官网注册一个,在这里我注册了一个huangbaokangtest@126.com在/etc/mail.rc文件末尾加入如下配置setfrom=huangbaokangtest@126.comsetsmtp=smtp.126.comsetsmtp-auth-user=huangbaokangtes…

    2022年10月20日
  • Python 学习笔记 列表 排序 xxx XXX

    Python 学习笔记 列表 排序 xxx XXXPython学习笔记列表排序xxxXXXprint(“-“*30)cars=[‘bmw’,’audi’,’toyota’,’subaru’]cars.sort()print(cars)print(“-“*30)cars=[‘bmw’,’audi’,’toyota’,’subaru’]cars.sort(reverse=True)print(cars)print(“-“…

    2022年8月22日
  • 笔记17-Map「建议收藏」

    笔记17-Map「建议收藏」1.Map集合1.1Map集合概述和特点【理解】Map集合概述interfaceMap<K,V>K:键的类型;V:值的类型Map集合的特点键值对映射关系一个键对应一个值键不能重复,值可以重复元素存取无序Map集合的基本使用publicclassMapDemo01{publicstaticvoidmain(String[]args){//创建集合对象Map<String,String&g

    2022年9月8日
  • Pytest(5)美化插件进度条pytest-sugar「建议收藏」

    Pytest(5)美化插件进度条pytest-sugar「建议收藏」前言在我们进行自动化测试的时候,用例往往是成百上千,执行的时间是几十分钟或者是小时级别。有时,我们在调试那么多用例的时候,不知道执行到什么程度了,而pytest-sugar插件能很好解决我们的痛点。

    2022年8月6日
  • exe免杀加壳工具包_grep过滤不想要的

    exe免杀加壳工具包_grep过滤不想要的简介该工具是由Arks7使用Go语言开发的一个免杀生成器模板,目前可以过国内主流杀毒。GitHub地址:https://github.com/Arks7/Go_Bypass用法使用CobaltStrike生成payload,输出格式为Raw,4.3版本需要勾选X64,如图:将生成的文件放在Go_Bypass项目目录下,然后执行goenv-wGOPROXY=https://goproxy.io,direct配置代理,否则编译报错。然后运行gorunmain.go,使用默认配置一路回车即

    2022年8月20日

发表回复

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

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