1.视频地址:
慕课讲解:
https://www.imooc.com/video/15090
2.寻找jar包:
http://mvnrepository.com/search?q=quartz
3.找到包包
4.
5.
6.
package com.ssm.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.stereotype.Component;
@Component("myBean")
public class MyBean {
public void printMessage(){
//打印当前时间格式:2017-01-01 00:00:00
Date date=new Date();
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("MyBean当前执行时间时间====="+sf.format(date));
System.out.println("MyBean开始执行=============打印我的bean============");
}
}
7.
package com.ssm.controller;
import org.springframework.stereotype.Component;
@Component("anotherBean")
public class AnotherBean {
public void printAnotherMessage(){
System.out.println("打印我的printAnotherMessage============AnotherBean");
}
}
8.
package com.ssm.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class FirstScheduledJob extends QuartzJobBean{
private AnotherBean anotherBean;
public void setAnotherBean(AnotherBean anotherBean){
this.anotherBean=anotherBean;
}
//复写
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
// TODO Auto-generated method stub
Date date=new Date();
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("FirstScheduledJob当前执行时间时间====="+sf.format(date));
System.out.println("FirstScheduledJob============执行");
this.anotherBean.printAnotherMessage();
}
}
运行即可!