Spirng quartz 整合
以下是资料来源:
quartz maven config
http://quartz-scheduler.org/downloads
Spring 定时器(Timer,Quartz)
http://superivan.iteye.com/blog/894900
quartz 使用方法(写得比较通俗易懂)
http://www.cnblogs.com/gantrylau/archive/2012/12/09/2809884.html
crontab配置详解
http://duqiangatom.blog.163.com/blog/static/1150251820107118467140/
配置xml注释
http://sunny.blog.51cto.com/182601/32366
quartz报错解决方案
http://pxjianke.iteye.com/blog/1897126
彻底理解spring的定制任务(scheduling)
http://wuhua.iteye.com/blog/67095
需求:
1、可定时处理任务
java代码:
package com.devops.task.QuartzJobTest; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.stereotype.Component; import com.devops.tEye.data.SysConfigData; import com.devops.tEye.service.TaskService; import com.devops.util.TimeUtil; /** * 自动发送邮件 * @author red * com.devops.tEye.email.EmailSendTask */ @Component("QuartzJobTest") public class QuartzJobTest extends QuartzJobBean { @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { try { System.out.println("执行发送邮件服务!"+TimeUtil.getCurDateTime()); } catch (Exception ex) { ex.printStackTrace(); } } }
applicationContext.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="reportJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> <property name="durability" value="true"></property> <property name="jobClass"> <value>com.devops.task.QuartzJobTest</value> </property> </bean> <bean id="cronReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="reportJob" /> <property name="cronExpression"> <value>0 0 12 * * ?</value> </property> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronReportTrigger"/> </list> </property> </bean> </beans>
然后在web.xml中配置:
<!-- 加载指定的资源文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:/applicationContext.xml </param-value> </context-param>
完毕!