您的位置:首页 > 编程语言 > Java开发

最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例

2016-12-18 00:00 477 查看
本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度。Spring 为简化 Quartz 的操作提供了相关支持类。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean id="fristJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.xx.schedule.FirstScheduledJob" />
<property name="jobDataMap">
<map>
<entry key="reportService" value-ref="reportService" />
</map>
</property>
<property name="durability" value="true" />
</bean>
<!-- Run the job every 5 seconds -->
<bean id="cronTrigger1"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="fristJobDetail" />
<!--<property name="cronExpression" value="0/5 * * ? * SAT-SUN" />-->
<property name="cronExpression" value="0/5 * * ? * *" />
</bean>
<bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!-- 延迟30秒启动Scheduler -->
<property name="startupDelay" value="10"></property>
<!--<property name="jobDetails">-->
<!--<list>-->
<!--<ref bean="fristJobDetail"/>-->
<!--</list>-->
<!--</property>-->
<property name="triggers">
<list>
<ref bean="cronTrigger1"/>
</list>
</property>
</bean>
</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: