Spring3.2.8集成Quartz2.2.1

 <!-- 1、定义JobDetail类 -->      
<bean id="testJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">     
    <property name="name" value="testJob"></property>     
    <property name="description" value="测试定时任务" />
    <property name="jobClass" value="somddomain.TestJob"></property>
    <property name="durability" value="true" />
</bean>      
   

<!-- 2、定义触发器 -->
    <bean id="testJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
     <property name="jobDetail" ref="testJobDetail"></property> 
     <property name="cronExpression" value="0 0 1 ? * *"></property>
 </bean> 
 

<!-- 定义调器器 -->

<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="startupDelay" value="60" />
    <property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceName">testQuartzScheduler</prop>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
            <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
            <prop key="org.quartz.threadPool.threadCount">3</prop>
            <prop key="org.quartz.threadPool.threadPriority">5</prop>
            <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.DB2v8Delegate</prop>
            <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS WHERE SCHED_NAME = {1} AND LOCK_NAME = ? FOR UPDATE</prop>
            <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop>
        </props>
    </property>
    <!-- scheduler by QuartzAdjust -->
    <property name="triggers">
        <list>
            <ref bean="testJobTrigger" />

        </list>
    </property>
    <property name="globalJobListeners">
        <list>
            <bean class="somedomain.TestJobListener"></bean>
        </list>
    </property>
</bean>

 

曾经碰到过一个这样的问题,在配置globalJobListeners时,一开始采用了如下的形式:

    <property name="globalJobListeners">
        <list>
            <ref bean="testJobListener" /> 

       </list>

    </property>

    <bean id="testJobListener" class="somedomain.TestJobListener"></bean>

然后,启动时报了这样的错:Non-global JobListeners not supported on Quartz 2 - manually register a Matcher against the Quartz ListenerManager instead

这句话的意思时,非全局的JobListeners在Quartz 2中已经不在支持,可以手工通过一个Matcher注册.

然而,错误的原因在于:spring启动后,发现显示定义了一个JobListener,就会注册到schedular上去,通过就种方法注册的是Non-global的,解决方法就是使用匿名的定义。这个注册的是一个全局的监听器,当然,如果有更加个性的需求,如只监听某个组下的定时任务,或某些个特定的定时任务,可以手工通过一个Matcher注册,,如:

scheduler.getListenerManager().addJobListener(myJobListener, KeyMatcher.jobKeyEquals(new JobKey("myJobName", "myJobGroup")));

 

你可能感兴趣的:(Spring3)