spring计划任务配置
xml配置
1 <!-- 德育记录48小时状态改变 --> 2 <bean id="moralEduRecordTask" class="org.springframework.scheduling.quartz.JobDetailBean"> 3 <property name="jobClass" value="com.ourquestion.tast.MoralEduRecordTask" /> 4 <property name="jobDataAsMap"> 5 <map> 6 <entry key="moralEduRecordServiceImpl"> 7 <ref bean="moralEduRecordServiceImpl"/> 8 </entry> 9 </map> 10 </property> 11 </bean> 12 13 <!-- 表达式配置 [秒] [分] [小时] [日] [月] [周] [年] 14 每半个小时 0 0/30 * * * ? 15 --> 16 <bean id="moralEduRecordTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean"> 17 <property name="jobDetail" ref="moralEduRecordTask"/> 18 <property name="cronExpression"> 19 <value>0 0/30 * * * ?</value> 20 </property> 21 </bean> 22 23 <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 24 <property name="triggers"> 25 <list> 26 <ref bean="moralEduRecordTriggerBean"/> 27 </list> 28 </property> 29 </bean>
对应的函数
1 public class MoralEduRecordTask extends QuartzJobBean{ 2 /** log4j对象 */ 3 private static final Logger log = Logger.getLogger(MoralEduRecordTask.class); 4 5 6 private MoralEduRecordServiceImpl moralEduRecordServiceImpl ; 7 8 9 @Override 10 protected void executeInternal(JobExecutionContext context) 11 throws JobExecutionException { 12 // TODO Auto-generated method stub 13 try { 14 log.info("---------- 德育考核开始执行任务 ----------"+context.getNextFireTime()); 15 moralEduRecordServiceImpl.updateMoralEduRecordStatus(context.getNextFireTime()); 16 } catch (Exception e) { 17 log.error("德育考核自动更新状态!", e); 18 } finally { 19 log.info("---------- 德育考核执行任务结束 ----------"); 20 } 21 } 22 23 24 public MoralEduRecordServiceImpl getMoralEduRecordServiceImpl() { 25 return moralEduRecordServiceImpl; 26 } 27 28 29 public void setMoralEduRecordServiceImpl(MoralEduRecordServiceImpl moralEduRecordServiceImpl) { 30 this.moralEduRecordServiceImpl = moralEduRecordServiceImpl; 31 } 32 33 34 35 }

浙公网安备 33010602011771号