@Bean
public JobDetail testQuartz02() {
return JobBuilder.newJob(TimerTask.class).withIdentity("testTask02").storeDurably().build();
}
@Bean
public Trigger testQuartzTrigger02() {
// cron方式,5秒执行一次
return TriggerBuilder.newTrigger().forJob(testQuartz02())
.withIdentity("testTask02")
.withSchedule(CronScheduleBuilder.cronSchedule("*/20 * * * * ?"))
.build();
}
public class TimerTask implements Job {
private Logger logger = LoggerFactory.getLogger(TimerTask.class);
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("11111");
}
}