我正在使用这种方法在Java EE中使用Quartz进行CDI:
public class CdiJobFactory implements JobFactory {
@Inject
private BeanManager beanManager;
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
Class<? extends Job> jobClass = bundle.getJobDetail().getJobClass();
Set<Bean<?>> beans = beanManager.getBeans(jobClass);
if (beans.isEmpty()) {
throw new SchedulerException("No job instance found for job class: " + jobClass.getName());
}
Bean<?> bean = beanManager.getBeans(jobClass).iterator().next();
CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
return (Job) beanManager.getReference(bean, jobClass, ctx);
}
}
一切正常,但是我在server.log中得到了所有石英作业和我注入它们的所有bean的错误消息(对于注入到石英作业中的EJB,该消息未记录):{{1 }}。作业成功执行,它们不会引发异常,但是我担心此错误消息。我尝试用[Payara 4.1] [SEVERE] No valid EE environment for injection of
或@ApplicationScoped
来注释作业,以此类推,但无济于事。我正在Payara Server 4.1.2.181上部署并使用Java EE 7。