<!-- 案例1 --> <!-- 定时器 --> <bean name="CodeTest" class="com.aaa.bbb.controller.cccc.dddd"></bean> <bean id="CodeTestDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用类 --> <property name="targetObject"> <ref bean="CodeTest"/> </property> <!-- 调用方法 --> <property name="targetMethod"> <value>testCode</value> </property> </bean> <!-- 定时器调度设置 --> <bean id="CodeTestTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <!-- 总调度设置 --> <property name="jobDetail"> <ref bean="CodeTestDetail"/> </property> <!-- 调度时效设置[秒 分 小时 日 月 周 年][年非必填][*所有值][-区间] --> <property name="cronExpression"> <!-- 每天凌晨00到01点调用一次 --> <value>0 0 00-01 * * ? *</value> <!-- 每10秒钟调用一次 --> <value>0/10 * * * * ? *</value> </property> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="CodeTestTrigger"/> </list> </property> </bean>
package com.aaa.bbb.controller.cccc; public class dddd { /** * 申诉时效过期设置。 * @throws Exception */ public void testCode() throws Exception{ syso("This is .... ..."); } }
<!-- 案例2 --> <bean id="exampleJob2" class="com.mhy.quartz.ExampleJob2"></bean> <bean id="exampleJob2Detail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 指定任务类 --> <property name="targetObject" ref="exampleJob2" /> <!-- 指定任务执行的方法 --> <property name="targetMethod" value="execute" /> </bean> <bean id="exampleJob2Trigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="exampleJob2Detail" /> <!-- 每1秒运行一次 --> <property name="cronExpression" value="0/1 * * * * ?" /> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="exampleJob2Trigger" /> </list> </property> </bean>