spring + Quartz定时任务配置
<bean id="exportBatchFileTask" class="com.ydcn.pts.task.ExportBatchFileTask"></bean> <bean id="readBatchFileTask" class="com.ydcn.pts.task.ReadBatchFileResultTask"></bean> <!-- 生成开卡档,停卡档,上传开卡停卡档,生成点数转移档 --> <bean id="executeExportOpenAndBlackCardFilesJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> //目标对象 <ref bean="exportBatchFileTask" /> //我们上面定义的定时任务bean </property> <property name="targetMethod"> //目标方法 <value>executeExportOpenAndBlackCardFiles</value> //我们在 ExportBatchFileTask 内部定义的方法的名称 </property> </bean> <!-- 上传点数转移档,上传--> <bean id="exeExportTransPointsFilesJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> //目标对象 <ref bean="exportBatchFileTask" /> //我们在上面定义的定时任务bean </property> <property name="targetMethod"> //目标方法 <value>uploadTransPointsBatchFiles</value> //在定时任务中的方法 </property> </bean> <!-- 定时下载批次档,插入数据库--> <bean id="downLoadBatchResultFilesJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="readBatchFileTask" /> </property> <property name="targetMethod"> <value>downLoadBatchResultFiles</value> </property> </bean> <!-- 解析所有结果档,插入数据库--> <bean id="execReadAllJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="readBatchFileTask" /> </property> <property name="targetMethod"> <value>execAll</value> </property> </bean> <!-- 读取CSV文件 --> <bean id="execReadCSVFileJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="readBatchFileTask" /> </property> <property name="targetMethod"> <value>readCSVFile</value> </property> </bean> <!-- 定义生成开卡停卡档,上传 触发时间 --> <bean id="executeExportOpenAndBlackCardFilesCron" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> //定时任务的工作详细 <ref bean="executeExportOpenAndBlackCardFilesJob" /> //我们上名定义的定时任务工作bean </property> <property name="cronExpression"> <value>0 30 15 * * ?</value> //定时任务工作的时间:value中[0 30 15 * * ?] 分别代表 [秒 分 时 天 月 ] </property> </bean> <!-- 定义生成点数转移详细,上传 触发时间 --> <bean id="exeExportTransPointsFilesCron" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="exeExportTransPointsFilesJob" /> </property> <property name="cronExpression"> <value>0 0 21 * * ?</value> </property> </bean> <!-- 定义读取文件目录,并且插入数据库 --> <bean id="downLoadBatchResultFilesCron" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="downLoadBatchResultFilesJob" /> </property> <property name="cronExpression"> <value>0 0/1 * * * ?</value> </property> </bean> <!-- 定义读取开卡结果的时间 --> <bean id="execReadAllCron" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="execReadAllJob" /> </property> <property name="cronExpression"> <value>0 0/1 * * * ?</value> </property> </bean> <!-- 读取csv文件 --> <bean id="execReadCSVFileCron" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="execReadCSVFileJob" /> </property> <property name="cronExpression"> <value>0 0/1 * * * ?</value> </property> </bean> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <!-- <ref bean="executeExportOpenAndBlackCardFilesCron" /> --> <!-- <ref bean="exeExportTransPointsFilesCron" /> --> <ref bean="downLoadBatchResultFilesCron" /> <ref bean="execReadAllCron"/> <!-- <ref bean="execReadCSVFileCron"/> --> </list> </property> </bean>
关于时间表达是的问题这里:http://www.cnblogs.com/skyblue/p/3296350.html 有详细的介绍,我在这里就不多说了。