Reputation: 21200
I received the error below when I use Spring 3 with Quartz 2. Does anyone knows the reason?
Error:
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.scheduling.quartz.JobDetailBean] for bean with name 'job' defined in class path resource [beans.xml]: problem with class file or dependent class; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.JobDetailBean has interface org.quartz.JobDetail as super class
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
Spring config file:
<bean name="job" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="Example.ExampleJob"/>
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5"/>
</map>
</property>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="job"/>
<property name="startDelay" value="1000"/>
<property name="repeatInterval" value="5000"/>
</bean>
public class ExampleJob extends QuartzJobBean {
private int timeout;
/**
* Setter called after the ExampleJob is instantiated
* with the value from the JobDetailBean (5)
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}
@Override
protected void executeInternal(JobExecutionContext ctx)
throws JobExecutionException {
*****
}
}
Upvotes: 25
Views: 34885
Reputation: 61
In my case, the problem was result from duplicate quartz lib. I have include a exclusion in pom.xml.
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core-hibernate</artifactId>
<version>5.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.openejb.shade</groupId>
<artifactId>quartz-openejb-shade</artifactId>
</exclusion>
</exclusions>
</dependency>
Upvotes: 0
Reputation: 651
If you use Spring 3.1,
Replace the SimpleTriggerBean with SimpleTriggerFactoryBean
In the 3.1 release, Spring has created Factory classes for crontrigger and simpletrigger
Update:
Using Spring 3.2.2, must be useful to change also JobDetailBean => JobDetailFactoryBean and CronTriggerBean => CronTriggerFactoryBean.
Credit to Osy (vote on the comment below)
Upvotes: 46
Reputation: 171
If You are using Spring 3.x & Quartz 2.1.x…
Then do only two changes IN YOUR configuration file 1st : for Simple Trigger
Use class=”org.springframework.scheduling.quartz.SimpleTriggerFactoryBean”>
instead of
class=”org.springframework.scheduling.quartz.SimpleTriggerBean”>
2nd : for Cron Trigger
use class=”org.springframework.scheduling.quartz.CronTriggerFactoryBean”
instead of
class=”org.springframework.scheduling.quartz.CronTriggerBean”
Upvotes: 17
Reputation: 2552
According to the 3.1.0.RC1 Change Log, Spring 3.1 has support for Quartz 2.x.
For every {Type}TriggerBean
there is now a {Type}TriggerBeanFactory
which can be used to setup triggers. In your case this would be SimpleTriggerFactoryBean
Excerpt
NOTE: This FactoryBean works against both Quartz 1.x and Quartz 2.0/2.1, in contrast to the older SimpleTriggerBean class.
Sidenote
You might also need to add the org.springframework.transaction dependency, depending on which type of trigger you are using:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
We needed it for migration to Quartz 2 in a configuration using CronTriggerFactoryBean
triggers.
Upvotes: 19
Reputation: 10843
Last I checked, Spring doesn't have support for Quartz 2. Either have a look to see if the most recent Spring builds have added said support, or try downgrading to Quartz 1.8.x.
Upvotes: 19