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


相关推荐

  • strstr函数 C++

    strstr函数 C++strstr函数分类: C/C++2011-08-1310:00 696人阅读 评论(0) 收藏 举报函数名:strstr功能:在串中查找指定字符串的第一次出现用法:char*strstr(char*str1,char*str2);程序例:#include#includeintmain(void){

    2022年6月25日
    23
  • 用tushare获取股票历史数据

    用tushare获取股票历史数据我们运用python进行量化分析的时候需要载入证券数据,tushare为我们提供了证券市场数据接口。tushare是以新浪财经、腾讯财经、上交所数据、深交所数据为基础提供的Python接口。安装方法为pipinstalltushare也可以到tushare的官网去下载,并且官网上有接口各个调用函数的详细说明http://tushare.org/index.html#id5

    2022年6月24日
    28
  • 线上问题排查,一不小心踩到阿里的 arthas坑了

    线上问题排查,一不小心踩到阿里的 arthas坑了

    2020年11月19日
    230
  • Proteus使用教程并仿真51程序——LED流水灯

    Proteus使用教程并仿真51程序——LED流水灯目录一、安装Proteus软件二、熟悉Proteus软件三、51程序设计和仿真四、总结五、参考资料Proteus是LabCenterElectronics公司推出的一个EDA工具软件。Proteus具有原理布图、PCB自动或人工布线、SPICE电路仿真、互动电路仿真、仿真处理器及其外围电路等特点功能。一、安装Proteus软件下面来了解下如何安装Proteus软件,安装过程也十分简单。首先需要下载Proteus的压缩包,链接如下。链接:https://pan.baidu.com/s/1e

    2022年5月10日
    51
  • vue前端跨域解决方案有哪些_前端能完全解决跨域问题吗

    vue前端跨域解决方案有哪些_前端能完全解决跨域问题吗为什么会出现跨域:浏览器访问非同源的网址时,会被限制访问,出现跨域问题.常见的跨域有三种:jspn跨域,原理:动态生成script标签,通过script标签引入接口地址(因为script标签不存在跨域的)cors跨域(后端开启):全称“跨域资源共享”,原理:它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJAX只能同源使用的限制vue代理服务器proxy跨域:通过请求本地的服务器,然后本地的服务器再去请求远程的服务器(后端部署接口的服务器),最后本地服务器再将请求

    2022年10月1日
    2
  • vue环境安装与配置(Linux安装常用开发工具)

    vue安装环境搭建提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录vue安装环境搭建前言一、node.js安装和配置1.下载安装node.js2.配置默认安装目录和缓存日志目录3.node.js环境配置4.配置淘宝镜像源二、使用步骤1.引入库2.读入数据总结前言vue前端框架的环境搭建一、node.js安装和配置1.下载安装node.js官网下载最新版本:https://nodejs.org/en/download/可以下载安装包(安装教程见:http

    2022年4月18日
    69

发表回复

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

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