targetMethod:指定将指定Bean实例的该方法包装成任务的执行体。
二、实例(JobDetailBean方式)
1、将spring核心jar包、quartz.jar和Spring-context-support.jar导入类路径。
2、编写Job类PunchJob(该类必须继承QuartzJobBean)
package org.crazyit.hrsystem.schedule;
import java.util.Date;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.crazyit.hrsystem.service.EmpManager;
public class PunchJob extends QuartzJobBean {
//判断作业是否执行的旗标
private boolean isRunning = false;
//该作业类所依赖的业务逻辑组件
private EmpManager empMgr;
public void setEmpMgr(EmpManager empMgr){
this.empMgr = empMgr;
}
//定义任务执行体
public void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
if (!isRunning){
System.out.println("开始调度自动打卡");
isRunning = true;
//调用业务逻辑方法
empMgr.autoPunch();
isRunning = false;
}
}
}
3、编写quartz.xml配置文件
1、配置文件:
*/5 * * * * ?
2、java类
public void executeExposure() throws Exception{
//1获取可变现的广告位
List listIis = adResourceIisDao.selectParam(new HashMap());
for (AdResource ad : listIis) {
Long id = ad.getId();
Integer expValue = adResourceIamsDao.count(id, "getExposureValue");
if (expValue != null) {
Map map = new HashMap();
map.put("expValue", expValue);
map.put("id", id);
adResourceIisDao.updateParam(map,"updateExp");
}
}