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


相关推荐

  • java cap理论_架构思想之CAP原理

    java cap理论_架构思想之CAP原理由于自己负责后端的设计已经有一段时间,对设计的一些思想和理论有一些理解,但最近被问到什么是CAP时,却一脸懵逼,下来后专门针对CAP架构思想进行了一些专题学习,在这里也将这个概念引入给大家,大家可以有意识地了解和学习这个思想理念,帮助自己在后续设计功能时有更好的参考。分布式领域CAP理论,Consistency(一致性),数据一致更新,所有数据变动都是同步的Availability(可用性),…

    2022年5月19日
    41
  • allocatememory(an out of memory)

    仅作为记录,大佬请跳过。仅需减小batchsize展示:即可运行。注博主的这个程序减小batchsize就行了,可能不同的博友们的程序不一样,也有的大佬博主使用不计算梯度或释放内存的方式不计算梯度——传送门withtorch.no_grad()释放内存——传送门ifhasattr(torch.cuda,’empty_cache’): torch.cuda.empty_cache()…

    2022年4月10日
    48
  • 在laravel框架中使用ajax请求报错419

    在laravel框架中使用ajax请求报错419

    2021年10月27日
    39
  • gg修改器修改数值没有用怎么办_gg修改器怎么用怎么修改数值 修改数值方法介绍…[通俗易懂]

    gg修改器修改数值没有用怎么办_gg修改器怎么用怎么修改数值 修改数值方法介绍…[通俗易懂]gg修改器怎么用怎么修改数值修改数值方法介绍GG修改器-全称GameGuardian是非常好用的手机修改器,但它需要ROOT权限,而现在要想ROOT一台手机难度是很大的,因此,本文介绍最新的GG修改免ROOT框架使用方法。现在市面上很多多开框架都支持ROOT,但支持最新安卓Q或者安卓11的却很少,并且运行GG修改器时会经常报错。并且,很多用户发现GG修改器也很难下载。X8沙箱,据说拥有完整系统级别…

    2022年9月5日
    2
  • 发包工具isic安装详解[通俗易懂]

    发包工具isic安装详解[通俗易懂]
    gentoolinux2.6
    isic版本:0.07,下载连接http://www.sfr-fresh.com/unix/privat/isic-0.07.tgz/
    依赖库libnet(版本1.1.5)下载连接http://sourceforge.net/projects/libnet-dev/ 或者 http://sourceforge.net/projects/libnet-dev/files/libnet-1.1.5.tar.gz/download

    2022年9月5日
    4

发表回复

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

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