Quartz两个定时任务的配置

来源:互联网 发布:海康威视网络配置设置 编辑:程序博客网 时间:2024/05/21 22:49

1、首先与spring进行整合,需要在spring的总配置中或者在web.xml中spring监听中加上

applicationContext-quartz.xml。 我是直接加了个xml文件。

注:根据自己的业务需要,设置定时器配置。


<?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:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">    <!-- 业务创建的定时任务 --><bean id="类名1" class="org.springframework.scheduling.quartz.JobDetailBean"><property name="jobClass"><value>类路径</value></property></bean><bean id="类名2" class="org.springframework.scheduling.quartz.JobDetailBean"><property name="jobClass"><value>类路径</value></property></bean>    <!-- 触发器配置  时间指定 -->  
<bean id="cronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail" ref="类名1" /><property name="cronExpression"><!--每10秒执行一次 --><value>0/10 * * * * ?</value></property></bean>
 <!-- 触发器配置  时间指定 -->  

<bean id="cronTrigger2" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail" ref="类名2" /><property name="cronExpression"><!--每10秒执行一次 --><value>0/10 * * * * ?</value></property></bean><!-- 总管理类 如果将lazy-init='false' 那么容器启动就会执行调度程序 --><bean id="schedulerFactoryBean" lazy-init="false" autowire="no"class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="configLocation" value="classpath:quartz.properties" /><property name="applicationContextSchedulerContextKey" value="applicationContext" /><property name="triggers"><list><ref bean="cronTrigger1" /><ref bean="cronTrigger2" /></list></property></bean></beans>




原创粉丝点击