Quartz与Spring的整合

1.ApplicationContext.xml配置文件




	
	
		
	

	
		
		
			
				
				
					
						uname
					
					Tom
				
			
		
	

	
	
	
	
	










2.job/JobSpring类

package job;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import biz.JobBiz;

public class JobSpring extends QuartzJobBean {
	private String uname;
	private JobBiz jobBiz;

	@Override
	protected void executeInternal(JobExecutionContext jobExecutionContext)
			throws JobExecutionException {
		System.out.println("========执行定时任务========");
		jobBiz.jobBiz();
		System.out.println(jobExecutionContext.getJobDetail().getJobDataMap().get("uname"));
	}

	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public JobBiz getJobBiz() {
		return jobBiz;
	}

	public void setJobBiz(JobBiz jobBiz) {
		this.jobBiz = jobBiz;
	}
}

3.Test类

package test;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import job.RemaindJob;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.AnnualCalendar;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {
	public static void main(String[] args) {
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
}

Quartz与Spring的整合_第1张图片

你可能感兴趣的:(Quartz与Spring的整合)