我正在尝试使用Quartz Scheduler,我正在Eclipse中编写一个小型测试程序,但是Eclipse编辑器在.withSchedule行中用红色表示。 .build();第二个括号和分号之间的行也有一个小的红色下划线。
当我将鼠标悬停在.withSchedule上时,Eclipse说:
“对于类型Date”
,未定义withSchedule(CalendarIntervalScheduleBuilder)方法以下是代码:
import static org.quartz.JobBuilder.*;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.CalendarIntervalScheduleBuilder.*;
import static org.quartz.JobKey.*;
import static org.quartz.TriggerKey.*;
import static org.quartz.DateBuilder.*;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
public class JobScheduler
{
Scheduler sched;
public JobScheduler()
{
try
{
SchedulerFactory schedFact = new StdSchedulerFactory();
sched = schedFact.getScheduler();
sched.start();
}
catch (SchedulerException e)
{
e.printStackTrace();
}
}
public void scheduleEmailJob(String from, String to, String subject, String message)
{
JobDetail job = newJob(EmailJob.class)
.withIdentity("myJob", "group1")
.usingJobData("from", from)
.usingJobData("to", to)
.usingJobData("subject", subject)
.usingJobData("message", message)
.build();
Trigger trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(tomorrowAt(15, 0, 0)
.withSchedule(calendarIntervalSchedule() // <------
.withIntervalInDays(1))
.build(); // <------
try
{
sched.scheduleJob(job, trigger);
}
catch (SchedulerException e)
{
e.printStackTrace();
}
}
}
有谁知道为什么会这样?
我在页面底部找到了代码段:
http://quartz-scheduler.org/documentation/quartz-2.2.x/cookbook/DailyTrigger
答案 0 :(得分:0)
尝试创建单独的作业类,并在主类中配置触发器,cron表达式和调度程序工厂。这会帮助你。
答案 1 :(得分:0)
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1").startNow().build();
使用它。