Spring集成Quartz定时任务 ---- 定时执行
一、依赖JAR包
<dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>1.8.4</version> </dependency>
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.0.5.RELEASE</version> </dependency
二、配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!--管理触发器的总设置 -->
<bean autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="QuartzSchedulerTrigger" />
</list>
</property>
</bean>
<bean id="QuartzScheduler"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<bean
class="com.service.task.QuartzSchedulerTask" /> //定义业务逻辑处理类
</property>
<property name="targetMethod">
<value>autoChecked</value>
</property>
<property name="concurrent">
<value>false</value>
</property>
</bean>
<bean id="QuartzSchedulerTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="QuartzScheduler" />
</property>
<property name="cronExpression"> //增加调度触发器
<!--秒 0-59 , - * / 分 0-59 , - * / 小时 0-23 , - * / 日期 1-31 , - * ? / L
W C 月份 1-12 或者 JAN-DEC , - * / 星期 1-7 或者 SUN-SAT , - * ? / L C # 年(可选) 留空,
1970-2099 , - * / -->
<value>0 0/1 * * * ?</value>
</property>
</bean>
</beans>
三、分析
Cron/
cronExpression
表达式“0 */1 * * * ?”意为:从0秒开始,每1分钟执行一次。
triggers属性中,我们可以增加多个触发器。
到此,Spring已经与Quartz完美的结合了,我们接下来的工作就是启动系统,开始调度了。
其他参考博客:http://www.cnblogs.com/obullxl/archive/2011/07/10/spring-quartz-cron-integration.html
http://kevin19900306.iteye.com/blog/1397744

浙公网安备 33010602011771号