Showing posts with label quartz. Show all posts
Showing posts with label quartz. Show all posts

Friday, January 14, 2011

classcastexception while working with quartz + spring

I was trying to integrate Quartz to Spring and while everything seemed OK I got the following exception:


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.

Wednesday, September 1, 2010

Could not calculate build plan: Missing: maven-resources-plugin:maven-plugin:2.4.1

While I was trying to take Quartz using Maven I got "Could not calculate build plan: Missing: maven-resources-plugin:maven-plugin:2.4.1" error. What now? Everything was working just fine!
To fix this, find where your local repo is, then go to "/.m2/repository/org/apache/maven/plugins/maven-resources-plugin/", remove "2.4.1" directory and do "update dependencies" from Maven.