春天 3 +石英2错误

发布于 2024-12-17 16:27:40 字数 1699 浏览 0 评论 0原文

当我将 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)

Spring 配置文件:

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

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

粉红×色少女 2024-12-24 16:27:40

如果使用 Spring 3.1,

请将 SimpleTriggerBean 替换为 SimpleTriggerFactoryBean

在 3.1 版本中,Spring 为 crontrigger 和 simpletrigger

Update 创建了 Factory 类:

使用Spring 3.2.2,一定有用,改一下JobDetailBean =>
JobDetailFactoryBean 和 CronTriggerBean => CronTriggerFactoryBean。

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

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)

薄荷梦 2024-12-24 16:27:40

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

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.

不疑不惑不回忆 2024-12-24 16:27:40

根据 3.1.0.RC1 变更日志,Spring 3.1 支持石英 2.x。

对于每个 {Type}TriggerBean,现在都有一个可用于设置触发器的 {Type}TriggerBeanFactory。在您的情况下,这将是 SimpleTriggerFactoryBean

摘录

注意:此 FactoryBean 适用于 Quartz 1.x 和 Quartz 2.0/2.1,与旧的 SimpleTriggerBean 类相反。

旁注

您可能还需要添加 org.springframework.transaction 依赖项,具体取决于您使用的触发器类型:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>3.1.2.RELEASE</version>
</dependency>

我们需要它在使用 CronTriggerFactoryBean触发器。

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.

亣腦蒛氧 2024-12-24 16:27:40

如果您使用 Spring 3.x & Quartz 2.1.x…

然后在您的配置文件中只进行两处更改
第一:对于简单触发器,

使用 class=”org.springframework.scheduling.quartz.SimpleTriggerFactoryBean”> 而不是
class=”org.springframework.scheduling.quartz.SimpleTriggerBean”>

第二个:用于 Cron 触发器
使用 class=”org.springframework.scheduling.quartz.CronTriggerFactoryBean” 而不是
class=”org.springframework.scheduling.quartz.CronTriggerBean”

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”

近箐 2024-12-24 16:27:40

就我而言,问题是由重复的石英库引起的。我在 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文