一、继承QuartzJobBean,重写executeInternal方法
<bean name="statQuartzJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.cn.zero.QuartzTask">
</property>
</bean>
<bean id="statTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="statQuartzJob"></property>
<property name="cronExpression" value="0 0/15 * * * ? *"/>
</bean>
二、不需要继承、实现任何对象
<bean id="statQuartzJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
// statQuartzJob为定义的bean(可以注解生成或者配置)
<property name="targetObject" ref="statQuartzJob" />
// 执行的方法
<property name="targetMethod" value="execute" />
<!-- 是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程 -->
<property name="concurrent" value="false" />
</bean>
(1)、<bean id="statQuartzJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="statQuartzJobDetail" />
<!-- 每天10点执行一次 -->
<property name="cronExpression" value="0 0 10 * * ?"/>
</bean>
<!--时间配置也可以-->
(2)、<bean name="statQuartzJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="statQuartzJobDetail"/>
<property name="startDelay" value="10000"/>
<property name="repeatInterval" value="600000"/>
</bean>
总:启动定时任务
<!--启动定时生成 数据 -->
<bean name="jsbfQuartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="statQuartzJobTrigger" />
</list>
</property>
</bean>