配置
<beans> <!--定义调度器--> <bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <!--注释掉 <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="applicationContextSchedulerContextKey" value="applicationContextKey"/> <property name="configLocation" value="classpath:quartz.properties"/> --> <property name="triggers"> <list> <ref bean="hxmxdzTaskTrigger"/> </list> </property> </bean> <!--处理类--> <bean id="hxmxdzTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="springQuartzTask"/> <property name="targetMethod" value="executeTask88"/> </bean> <!--定义触发器--> <bean id="hxmxdzTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="hxmxdzTask"/> <!--可循环跑,从晚上9点开始处理,20分钟处理一次,但是只处理到当天晚上11.00--> <property name="cronExpression" value="0 0/20 21-23 * * ?"/> </bean> </beans>
@Component("springQuartzTask") public class SpringQuartzTask{ }