java Bean石英注入空指针异常
我遇到了一个问题,在Quartz schedule作业中注入CDIBean。我在quartz中为我的接口添加了自定义CDIJobFactory
。当quartz方法在Jboss eap 6.4上执行时,它是抛出错误
java.lang.IllegalArgumentException: JobFactory cannot be set to null!
最初,我尝试使用EJB定时器(@Schedule annotation),但EJB定时器不起作用,控制台也没有任何问题,所以我不知道如何进一步使用EJB定时器,然后我开始使用quartz
所以,如果我在quartz中错过了什么或者做错了什么,请告诉我,因为我对quartz、EJB和jboss服务器是全新的
CDIJobFactory。班级
@ApplicationScoped
public class CDIJobFactory implements JobFactory {
@Inject @Any
private Instance<Job> jobs;
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
final Class<? extends Job> clazz = bundle.getJobDetail().getJobClass();
final Instance<? extends Job> bean = jobs.select(clazz);
if (bean.isUnsatisfied()) throw new SchedulerException("No job bean of type " + clazz + " found.");
return bean.get();
}
}
安排工作。班级
@ApplicationScoped
public class ScheduleJob {
private Scheduler scheduler;
@Inject
private CDIJobFactory jobFactory;
public void cronInitialized() {
try {
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.setJobFactory(jobFactory); // jobFactory throwing null exception
} catch (final SchedulerException | RuntimeException schedEx) {
System.out.println("Problem loading Quartz!"+ schedEx);
}
JobDetail jobDetail = JobBuilder.newJob(messageJob.class)
.withIdentity(ImagesProcessJob.class.getSimpleName())
.build();
CronTrigger trigger = TriggerBuilder.newTrigger()
.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.forJob(jobDetail).build();
try {
scheduler.scheduleJob(jobDetail, trigger);
scheduler.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
messageJob。班级
@ApplicationScoped
public class messageJob implements Job {
@Inject DNOWorkflowBO dnoWorkflowBO;
public messageJob() {}
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
dnoWorkflowBO.dnoCronJob(); // this line throwing null pointer exception
} catch(Exception e) {
throw new JobExecutionException(e);
}
}
}
BODAppInitServlet。班级
public class BODAppInitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void init(ServletConfig config) throws ServletException {
try {
new ScheduleJob().cronInitialized();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
共 (0) 个答案