<beans default-lazy-init="true" default-autowire="byName">
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false">
<property name="triggers">
<list><ref bean="clearLogsTrigger" /></list>
</property>
</bean>
...
</beans>
如果default-autowire="byName",则此时会产生如下错误:
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
解决:自动装配惹得祸,存在dataSource这个bean就自动用数据库的状态维持了。故去掉default-autowire="byName"
原因:此时的quartz是jobstore用的HDBCJobStore模式,此时会从数据库查询任务。
quartz应该是使用数据进行job的状态的维护的,但是在数据库中没有找到相应的table,从而无法正常建立scheduler 。
即使是采取内存存储的模式,配置如下:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="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>
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.