我正在尝试创建一个重新安排触发器的方法。当我尝试按照official quartz documentation中的教程进行操作时,我在我的reschedule()方法中遇到错误
对于Trigger
类型,未定义getTriggerBuilder()方法
和
对于Trigger类型
,方法getKey()未定义
when(any(MyObject).class).getValue().thenReturn("something");
为什么我会收到这些错误? Eclipse似乎没有认识到Quartz的API?
我的pom.xml具有Quartz的这些依赖关系:
import static org.quartz.JobBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import static org.quartz.CronScheduleBuilder.*;
import static org.quartz.CalendarIntervalScheduleBuilder.*;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.DateBuilder.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
@Component
public class OrgReportScheduler {
@Autowired
private SchedulerFactoryBean schedulerFactoryBean;
public void beginSchedule(String cronStr) throws Exception {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
scheduler.start();
JobDetail job = newJob(OrgReportJob.class).withIdentity("OrgReportJob", "group1").build();
Trigger trigger = newTrigger().withIdentity("OrgReportTrigger", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule(cronStr)).forJob("OrgReportJob").build();
// schedule it
scheduler.scheduleJob(job, trigger);
}
public void reschedule(String cronStr) {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
Trigger oldTrigger = scheduler.getTrigger("OrgReportTrigger", "group1");
TriggerBuilder tb = oldTrigger.getTriggerBuilder();
// update the schedule associated with the builder, and build the new trigger
// (other builder methods could be called, to change the trigger in any desired way)
Trigger newTrigger = tb.withSchedule(simpleSchedule()
.withIntervalInSeconds(10)
.withRepeatCount(10))
.build();
scheduler.rescheduleJob(oldTrigger.getKey(), newTrigger);
}
}