弹簧版:2.0.7与石英集成?

时间:2011-05-19 21:16:03

标签: spring quartz-scheduler

我正在使用Spring-Version:2.0.7,我是否需要下载石英库及其依赖项才能使用它?起初我虽然需要但它给了我一个java.lang.IncompatibleClassChangeError。

所以我认为它可能是在spring.jar中集成的,因为根据2.5 spring,在弹簧库的应用程序上下文中调用bean。

当我删除quarta.jar时,我无法访问JobExecutionContext类。这是我的bean声明:

<bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.bamboo.common.util.CheckAndProcessFilesJob" />
    <property name="jobDataAsMap">
    <map>
      <entry key="timeout" value="5" />
    </map>
    </property>
</bean>

java代码

package com.bamboo.common.util;

import org.springframework.scheduling.quartz.QuartzJobBean;


    /**
     * Created by IntelliJ IDEA.
     * User: ernestobuttolazio
     * Date: 19-may-2011
     * Time: 16:44:54
     * To change this template use File | Settings | File Templates.
     */
    public class CheckAndProcessFilesJob extends QuartzJobBean {
        private int timeout;

        private int contador;
         /**
       * Setter called after the ExampleJob is instantiated
       * with the value from the JobDetailBean (5)
       */
      public void setTimeout(int timeout) {
        this.timeout = timeout;
      }

     protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
          // do the actual work
         contador += timeout;
      }

    }

3 个答案:

答案 0 :(得分:3)

你需要使用石英2.1.6。应该使用JobDetailFactoryBean代替JobDetailBean。配置看起来像,

    <bean name="sampleJobDetail"
            class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
            <property name="jobClass"
                value="com.altisource.scheduler.jobs.SampleJob" />
            <property name="jobDataAsMap">
                <map>
                </map>
            </property>

        </bean>

        <bean id="sampleTrigger"
            class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
            <property name="jobDetail" ref="sampleJobDetail" />
            <property name="startDelay" value="30000" />
            <property name="repeatInterval" value="30000" />
            <property name="group" value="YOURCHOICE" />
        </bean>

如果您正在使用带有群集的石英,则调度程序工厂org.springframework.scheduling.quartz.SchedulerFactoryBean将仅使用属性triggers并限制提供jobDetails。确保仅使用org.springframework.scheduling.quartz.SchedulerFactoryBean配置调度程序工厂triggers

答案 1 :(得分:2)

你需要在Spring的当前包装器中使用Quartz 1.8.x或更早版本。 Quartz 2.0无法使用它们。

你可以在Spring上使用Quartz 2.0没问题 - 只是没有使用Spring的包装器。

答案 2 :(得分:1)

Quartz 2.x版本与spring不兼容。早期版本的某些类已转换为quartz 2.x中的接口。但它仍然可以在没有它的集成支持的帮助下与spring一起使用。 查看此链接http://shyarmal.blogspot.com/2011/07/quartz-20-schedule-cron-with-spring.html