开发者

Spring-Version: 2.0.7 integrated with quartz?

开发者 https://www.devze.com 2023-03-07 16:01 出处:网络
i\'m using Spring-Version: 2.0.7, do i need to download quartz libraries and their dependencies to use it ? cause at first i though it was needed but its giving me an java.lang.IncompatibleClassChange

i'm using Spring-Version: 2.0.7, do i need to download quartz libraries and their dependencies to use it ? cause at first i though it was needed but its giving me an java.lang.IncompatibleClassChangeError.

So i figured that maybe it was integrated in the spring.jar since according to the 2.5 spring the bean is invoked on the application context trhough the spring library.

How ever when i removed quarta.jar, i can´t acces the JobExecutionContext class. Here is my bean declaration:

<bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.bamboo.common.util.CheckAndProcess开发者_开发百科FilesJob" />
    <property name="jobDataAsMap">
    <map>
      <entry key="timeout" value="5" />
    </map>
    </property>
</bean>

The java code

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;
      }

    }


You need to use quartz 2.1.6. JobDetailFactoryBean should be used in place of JobDetailBean.The configuration will look like,

    <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>

If your are using quartz with clustering, the scheduler factory org.springframework.scheduling.quartz.SchedulerFactoryBean will take only property triggers and restrict providing jobDetails. Make sure you configure scheduler factory org.springframework.scheduling.quartz.SchedulerFactoryBean with only triggers.


You need to use Quartz 1.8.x or earlier with Spring's current wrappers. Quartz 2.0 does not work with them.

You can use Quartz 2.0 along side Spring no problem - just not with Spring's wrappers.


Quartz 2.x versions are not compatible with spring. Some classes of the earlier versions have been converted to interfaces in quartz 2.x. But still it can be used with spring, without the help of it's integration support. Check out this link http://shyarmal.blogspot.com/2011/07/quartz-20-schedule-cron-with-spring.html.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号