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.

 

补单系统源码

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • linux中ll排序命令,ll命令

    linux中ll排序命令,ll命令-a列出目录下所有的文件,包括.开头的隐藏文件-A列出目录下所有的文件,不包括.开头的隐藏文件-c配合-lt:根据ctime排序及显示ctime(文件状态最后更改的时间)配合-l:显示ctime但根据名称排序否则:根据ctime排序-C每栏由上至下列出项目–color[=WHEN]控制是否使用色彩分辨文件。WHEN可以是‘never‘、‘always‘或‘auto‘…

  • mysql DatabaseMetaData使用说明[通俗易懂]

    mysql DatabaseMetaData使用说明[通俗易懂]DatabaseMetaData数据库元数据,这一名词经常在软件平台中出现,特别是支持多种数据库的平台,主要用于获取数据库信息,便于系统对数据库更好的适配。

  • xmind打不开xmind文件_鼠标双击无法打开文件

    xmind打不开xmind文件_鼠标双击无法打开文件声明:请大家支持正版!此文仅作个人交流学习!很多小伙伴安装完Xmind后会发现双击无法打开文件,只能在应用界面打开,我在网上也看了很多解决方案,但是很多都是没用的,比如这个:还有说把最大支持的文件大小改成128m,亲测没用。还有想着把pojie包配置给注释掉的,这种可能也是为了支持正版吧/手动狗头后来试了很多方法,发现更改一下pojie包的路径就好了,改成绝对路径就可以直接打开。我用的是xmind8update9版本,亲测可行,如果其他版本的小伙伴试了不行的话,可以评论区一起交流一下~..

    2022年10月24日
  • Python基础(1):基本规则及赋值「建议收藏」

    Python基础(1):基本规则及赋值「建议收藏」Python有如下的基本规则:#后表示注释\n是行分隔符\是继续上一行,将过长语句分开;分号将两个语句连接在一行中:冒号将代码头和体分开代码块用缩进块的方式体现不同缩进深度分隔不同的代码

  • chrome离线安装包下载_谷歌浏览器的离线安装包

    chrome离线安装包下载_谷歌浏览器的离线安装包有能力的可以自行到下方地址下载:最新稳定版:https://www.google.com/intl/zh-CN/chrome/browser/?standalone=1最新测试版:https://

  • eMule 站点收集[通俗易懂]

    eMule 站点收集[通俗易懂]http://www.simplecd.org/http://qvocd.com/http://www.ied2k.com/http://www.thshare.net/http://www.eastgame.nethttp://www.chnp2p.com/http://www.hatrix.org/http://www.emule-ed2k.com/htt…

发表回复

您的电子邮箱地址不会被公开。

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