java.lang.ClassCastException: org.quartz.impl.StdScheduler
I had everything in hand for the simple job I implemented to work.
A simple Job class that implements QuartzJobBean:
public class Job extends QuartzJobBean{
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("working!");
}
}
The necessary spring context:
All I had to do is instantiate the bean with getBean() but I was getting "java.lang.ClassCastException: org.quartz.impl.StdScheduler" everytime. My code for instantiating the SchedulerFactoryBean was below:
SchedulerFactoryBean d = (SchedulerFactoryBean) appCon.getBean("scheduler");
I was trying to downcast to a wrong class. It seemed quite straightforward to use SchedulerFactoryBean but it was wrong. As the exception said I changed it to StdScheduler (of Quartz) and I fixed it.
Here's the correct form:
StdScheduler d = (StdScheduler) appCon.getBean("scheduler");
I hope that easy solution will be helpful for somebody out there.
No comments:
Post a Comment