1.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean name="job" class="com.siyuan.test.quartz.job.LogJob"></bean>
<bean name="jobDetail"
class="frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean">
<property name="targetBean" value="job" />
<property name="targetMethod" value="execute" />
<property name="group" value="scheduler" />
<!--
<property name="shouldRecover" value="true" />
-->
</bean>
<bean name="trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="0/2 * * * * ?" />
<property name="name" value="trigger" />
<property name="group" value="scheduler" />
</bean>
<bean name="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="trigger" />
</list>
</property>
<property name="configLocation" value="classpath:quartz.properties"/>
<!--
<property name="overwriteExistingJobs" value="true" />
-->
</bean>
</beans>
必须使用frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean
或者frameworkx.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean,
直接使用org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean会报java.io.NotSerializableException异常,参考http://jira.springframework.org/browse/SPR-3797
这里也可以自己写一个类继承QuartzJobBean来作为我们要执行的Job
shouldRecover 当Quartz服务被中止后,再次启动或集群中其他机器接手任务时会尝试恢复执行之前未完成的所有任务
overwriteExistingJobs 必须设置为TRUE,否则配置文件中的更新无法影响DB已存在的信息
通过NAME和GROUP识别
quartz.properties:
#org.quartz.jobStore.isClustered = true
#org.quartz.jobStore.clusterCheckinInterval = 20000