Spring中这样配置:
<bean id="quartzdataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@192.168.0.44:1521:orcl" />
<property name="username" value="orawms" />
<property name="password" value="orawms" />
</bean>
<bean id="scheduleReportFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="dataSource">
<ref bean="quartzdataSource" /> Spring中对于的数据源
</property>
<property name="startupDelay" value="100" />
<property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
<property name="configLocation" value="classpath:quartz.properties" />
</bean>配置好数据源dataSource后,需要在Quartz的QRTZ_LOCKS表中插入以下数据:
INSERT INTO QRTZ_LOCKS values('TRIGGER_ACCESS');
INSERT INTO QRTZ_LOCKS values('JOB_ACCESS');
否则会报
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduler' defined in file [...\webapps\WEB-INF\classes\config\applicationContext-quartz.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: No row exists in table QRTZ_LOCKS for lock named:
TRIGGER_ACCESS [See nested exception: java.sql.SQLException: No row exists in table QRTZ_LOCKS for lock named: TRIGGER_ACCESS]]异常
●dataSource:当需要使用数据库来持久化任务调度数据时,你可以在Quartz中配置数据源,也可以直接在Spring中通过dataSource指定一个Spring管理的数据源。如果指定了该属性,即使quartz.properties中已经定义了数据源,也会被此dataSource覆盖;
转载请注明原文地址: https://ju.6miu.com/read-965664.html