See the point? Suppose we have some cyclic reference in the context and SchedulerFactoryBean relies on some other beans (for example, they may be needed for initial state configuration), and some of those other beans relies on scheduler in order to do some job later. Now if other beans happen to be created earlier then SchedulerFactoryBean (though, maybe not fully initialized) then everything works fine - half-ready beans are injected in SchedulerFactoryBean. But if scheduler factory gets created first then it tries to initialize another beans, which in they turn try to get Scheduler instance - and bang!!
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'quartzScheduler': FactoryBean which is currently in creation returned null from getObject
This was in Spring 3.1So, beware of this problem and avoid including SchedulerFactoryBean in cyclic references.
Hi,
ReplyDeleteI am also facing the same problem. When I tried to create or get reference of scheduler from SchedulerFactoryBean it return null
------------
JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
jobDetailFactoryBean.setJobClass(MyQuartzJobTest.class);
SimpleTriggerFactoryBean simpleTriggerFactoryBean = new SimpleTriggerFactoryBean();
simpleTriggerFactoryBean.setJobDetail(jobDetailFactoryBean.getObject());
simpleTriggerFactoryBean.setStartDelay(20000);
simpleTriggerFactoryBean.setRepeatInterval(20000);
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setTriggers(new Trigger[]{simpleTriggerFactoryBean.getObject()});
Scheduler scheduler = schedulerFactoryBean.getObject();
try{
//scheduler.start();
schedulerFactoryBean.start();
}catch(Exception e){
System.out.println(" ..... Scheduler can not be started ... : error : "+e);
e.printStackTrace();
}
-------------------
Yes i experienced the same issue, not sure if latest release of quartz and spring have taken care of this issue, am using quartz 2.2 and spring 3.5 and i still see this behaviour where while initializting schedulerfctotybean, we need to explicityly ccall afterpropertieset which is kind of unsafe iguess
ReplyDelete