io.dropwizard.jobs.SpringJobFactory Maven / Gradle / Ivy
package io.dropwizard.jobs;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.spi.JobFactory;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.context.ApplicationContext;
public class SpringJobFactory implements JobFactory {
ApplicationContext context;
public SpringJobFactory(ApplicationContext context) {
this.context = context;
}
@Override
public Job newJob(TriggerFiredBundle triggerFiredBundle, Scheduler scheduler) throws SchedulerException {
JobDetail jobDetail = triggerFiredBundle.getJobDetail();
Class extends Job> jobClass = jobDetail.getJobClass();
return context.getBean(jobClass);
}
}