弹簧 3 + 石英 2 错误

2022-09-01 21:32:04

当我将Spring 3与Quartz 2一起使用时,我收到了以下错误。有人知道原因吗?

错误:

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)

弹簧配置文件:

<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 {
        *****
    }

}

答案 1

如果您使用 Spring 3.1,

将 SimpleTriggerBean 替换为 SimpleTriggerFactoryBean

在3.1版本中,Spring为crontrigger和simpletrigger创建了Factory类。

更新:

使用Spring 3.2.2,必须有用的是更改JobDetailBean => JobDetailFactoryBean和CronTriggerBean => CronTriggerFactoryBean。

感谢Osy(对下面的评论进行投票)


答案 2

最后我检查了一下,Spring不支持Quartz 2。要么看看最近的Spring版本是否增加了上述支持,要么尝试降级到Quartz 1.8.x。


推荐