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)
上一篇 2022年5月23日 下午6:40
下一篇 2022年5月23日 下午6:40


相关推荐

  • ICMP详解「建议收藏」

    ICMP详解「建议收藏」ICMP(InternetControlMessageProtocol)网际控制报文协议。它是TCP/IP协议簇的一个子协议,用于在IP主机、路由器之间传递控制消息。控制消息是指网络通不通、主机是否可达、路由是否可用等网络本身的消息。这些控制消息虽然并不传输用户数据,但是对于用户数据的传递起着重要的作用。ICMP使用IP的基本支持,就像它是一个更高级别的协议,但是,ICMP实际上是IP的…

    2022年7月12日
    22
  • 三次握手几个rtt_tcp三次握手详细过程

    三次握手几个rtt_tcp三次握手详细过程一、RST包、本人学习后总结:RST包用于强制关闭TCP链接。TCP连接关闭的正常方法是四次握手。但四次握手不是关闭TCP连接的唯一方法.有时,如果主机需要尽快关闭连接(或连接超时,端口或主机不可达),RST(Reset)包将被发送.注意,由于RST包不是TCP连接中的必须部分,可以只发送RST包(即不带ACK标记).但在正常的TCP连接中RST包可以带ACK确认标记。 二、三次握手Th…

    2022年10月1日
    5
  • Qt QStringList的简单使用方法「建议收藏」

    Qt QStringList的简单使用方法「建议收藏」从QList继承而来,它提供快速索引为基础的接入以及快速插入和清除其成员函数用于操作这个字符串列表如append(),insert(),replace(),removeAll(),removeAt(),removeFirst(),removeLast(),andremoveOne()等1.  增加字符串  可以通过append(),或使用  QString

    2022年6月4日
    100
  • Delphi ord 函数

    Delphi ord 函数1 ord 函数 Returns nbsp the nbsp ordinal nbsp value nbsp of nbsp an nbsp ordinal type nbsp expression 返回一个序数类型表达式的序数值 nbsp Example uses nbsp Dialogs type nbsp nbsp nbsp Colors nbsp nbsp RED BLUE GREEN var nbsp nbsp S nbsp string nbsp begin nbsp nbsp nbsp S nbsp nbsp BLUE nbsp has nbsp an nbsp ordinal nbsp value nbsp

    2026年3月17日
    2
  • NAT的双机热备方案

    一般的NAT组网中,内网用户通过单台设备进行NAT转换访问外网,NAT设备承担了所有内外网之间的流量,无法规避单点故障。一旦发生单点故障,将导致内网用户无法与外网通信。随着用户对网络可靠性的要求越来越高,发生单点故障导致网络间断是不可接受的。因此在重要节点处一般都部署两台或者多台设备,构成冗余备份组网,但如果设备之间不能实时的进行数据备份的话,链路切换时还是会导致用户的业务中断。双机热备方案可…

    2022年4月7日
    92
  • OpenClaw连接Slack配置完整教程

    OpenClaw连接Slack配置完整教程

    2026年3月13日
    5

发表回复

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

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