使用 Spring 框架的 Quartz JobStore

发布于 2024-07-29 08:33:24 字数 1639 浏览 3 评论 0原文

我正在使用 Spring 框架在 Oracle DB 上实现 Quartz Job Store。 我的 ApplicationContext.xml 如下

<bean id="driverJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="BatchFileCollector" />
</bean>

<bean id="ranchTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="driverJob" />
    <property name="startDelay" value="2000" />
    <property name="repeatInterval" value="10000" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="ranchTrigger" />
        </list>
    </property>
    <property name="dataSource">
        <ref bean="dataSource.TEXAN"/>
    </property>
    <property name="applicationContextSchedulerContextKey">
        <value>applicationContext</value>
    </property>
    <property name="autoStartup">
        <value>true</value>
    </property>
    <property name="configLocation" value="classpath:quartz.properties"/>
</bean>

此配置给了我以下错误。

Caused by: org.quartz.JobPersistenceException: 

Couldn't store trigger: The job (DEFAULT.driverJob) referenced by the trigger does not exist. 

[See nested exception: org.quartz.JobPersistenceException: The job (DEFAULT.driverJob) referenced by the trigger does not exist.]

我正在使用 Spring 框架 2.5.6。 我必须升级我的 Quartz 版本吗? 我找不到问题所在。

感谢您的帮助。

I am implementing Quartz Job Store on Oracle DB using Spring Framework. My ApplicationContext.xml is below

<bean id="driverJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="BatchFileCollector" />
</bean>

<bean id="ranchTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="driverJob" />
    <property name="startDelay" value="2000" />
    <property name="repeatInterval" value="10000" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
        <list>
            <ref bean="ranchTrigger" />
        </list>
    </property>
    <property name="dataSource">
        <ref bean="dataSource.TEXAN"/>
    </property>
    <property name="applicationContextSchedulerContextKey">
        <value>applicationContext</value>
    </property>
    <property name="autoStartup">
        <value>true</value>
    </property>
    <property name="configLocation" value="classpath:quartz.properties"/>
</bean>

This configuration gives me the below error.

Caused by: org.quartz.JobPersistenceException: 

Couldn't store trigger: The job (DEFAULT.driverJob) referenced by the trigger does not exist. 

[See nested exception: org.quartz.JobPersistenceException: The job (DEFAULT.driverJob) referenced by the trigger does not exist.]

I am using Spring Framework 2.5.6. Do I have to upgrade my Quartz version?
I cannot find the problem.

Thanks for your help.

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

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

发布评论

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

评论(3

醉生梦死 2024-08-05 08:33:24

您的 SchedulerFactoryBean 还需要注册“driverJob”。 除了触发器之外,还添加 jobDetails 列表。

<bean id="job.statistics.DailyQPSValidationJobTrigger" class="org.quartz.CronTrigger">
    <property name="name" value="DailyQPSValidationTrigger" />
    <property name="jobName" value="DailyQPSValidation" />
    <property name="jobGroup" value="Statistics" />
    <property name="volatility" value="false" />
    <!-- Each day, 4 o'clock AM -->
    <property name="cronExpression" value="0 0 4 * * ?" />
</bean>

<!-- Scheduler -->

<bean id="job.SchedulerProperties" class="somecompany.someproduct.util.spring.PropertiesFactoryBean"
    scope="singleton">
    <property name="source">
        <props>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
            <prop key="org.quartz.scheduler.instanceName">JobCluster</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.jobStore.useProperties">false</prop>
        </props>
    </property>
</bean>

<bean id="job.Scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton"
    lazy-init="false">
    <property name="startupDelay" value="30" />
    <property name="waitForJobsToCompleteOnShutdown" value="true" />
    <property name="dataSource" ref="jdbc.DataSource" />
    <property name="quartzProperties" ref="job.SchedulerProperties" />
    <property name="jobDetails">
        <list>
            <ref bean="job.statistics.DailyQPSValidationJobDetail" />
        </list>
    </property>
    <property name="triggers">
        <list>
            <ref bean="job.statistics.DailyQPSValidationJobTrigger" />
        </list>
    </property>
    <property name="schedulerListeners">
        <list>
            <bean class="somecompany.someproduct.job.SchedulerErrorListener">
                <property name="monitoringService" ref="monitoring.MonitoringService" />
            </bean>
        </list>
    </property>
    <property name="globalJobListeners">
        <list>
            <bean class="somecompany.someproduct.job.JobErrorListener">
                <property name="name" value="JobErrorListener" />
                <property name="monitoringService" ref="monitoring.MonitoringService" />
            </bean>
        </list>
    </property>
</bean>

Your SchedulerFactoryBean needs to have the "driverJob" registered, too. Along with your triggers, add a list of jobDetails.

<bean id="job.statistics.DailyQPSValidationJobTrigger" class="org.quartz.CronTrigger">
    <property name="name" value="DailyQPSValidationTrigger" />
    <property name="jobName" value="DailyQPSValidation" />
    <property name="jobGroup" value="Statistics" />
    <property name="volatility" value="false" />
    <!-- Each day, 4 o'clock AM -->
    <property name="cronExpression" value="0 0 4 * * ?" />
</bean>

<!-- Scheduler -->

<bean id="job.SchedulerProperties" class="somecompany.someproduct.util.spring.PropertiesFactoryBean"
    scope="singleton">
    <property name="source">
        <props>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
            <prop key="org.quartz.scheduler.instanceName">JobCluster</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.jobStore.useProperties">false</prop>
        </props>
    </property>
</bean>

<bean id="job.Scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" scope="singleton"
    lazy-init="false">
    <property name="startupDelay" value="30" />
    <property name="waitForJobsToCompleteOnShutdown" value="true" />
    <property name="dataSource" ref="jdbc.DataSource" />
    <property name="quartzProperties" ref="job.SchedulerProperties" />
    <property name="jobDetails">
        <list>
            <ref bean="job.statistics.DailyQPSValidationJobDetail" />
        </list>
    </property>
    <property name="triggers">
        <list>
            <ref bean="job.statistics.DailyQPSValidationJobTrigger" />
        </list>
    </property>
    <property name="schedulerListeners">
        <list>
            <bean class="somecompany.someproduct.job.SchedulerErrorListener">
                <property name="monitoringService" ref="monitoring.MonitoringService" />
            </bean>
        </list>
    </property>
    <property name="globalJobListeners">
        <list>
            <bean class="somecompany.someproduct.job.JobErrorListener">
                <property name="name" value="JobErrorListener" />
                <property name="monitoringService" ref="monitoring.MonitoringService" />
            </bean>
        </list>
    </property>
</bean>
嘿嘿嘿 2024-08-05 08:33:24

我对 Quartz 1.5.2 和 Spring 3.0.4 也有同样的问题。 问题在于 JobStoreSupport 类尝试存储带有作业外键的 cron 触发器(尝试从数据库加载作业),但该触发器尚未持久化。

quartz 1.6.1、1.7.2 版本也有同样的问题。

<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
      depends-on="quartzDatabaseCreator">
    <property name="autoStartup">
        <value>true</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?
            </prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.${qrtz.delegateClass}
            </prop>
        </props>
    </property>
    <property name="triggers">
        <list>
            <ref bean="cronTrigger"/>
        </list>
    </property>
    <property name="schedulerContextAsMap">
        <map>
            <entry key="sygnoServerHelper"><ref bean="sygnoServerHelper"/></entry>
            <entry key="requestDAO"><ref bean="requestDAO"/></entry>
            <entry key="alairoCache"><ref bean="alairoCache"/></entry>
        </map>
    </property>
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="checkGracePeriodJob" />
    <!--                                 # s m h dom mon dow [y]  -->
    <property name="cronExpression" value="0 0/5 * * * ?" />
</bean>

<bean id="checkGracePeriodJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="com.synergon.sygnoserver.CheckGracePeriodJob"/>
 </bean>

I have the same problem with Quartz 1.5.2 and Spring 3.0.4. The problem is that the JobStoreSupport class tries to store a cron trigger with a foreign key to the job (tries to load the job from the db), which is not persisted yet.

Same problem with quartz 1.6.1, 1.7.2 versions.

<bean id="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
      depends-on="quartzDatabaseCreator">
    <property name="autoStartup">
        <value>true</value>
    </property>
    <property name="dataSource">
        <ref bean="dataSource"/>
    </property>
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?
            </prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.${qrtz.delegateClass}
            </prop>
        </props>
    </property>
    <property name="triggers">
        <list>
            <ref bean="cronTrigger"/>
        </list>
    </property>
    <property name="schedulerContextAsMap">
        <map>
            <entry key="sygnoServerHelper"><ref bean="sygnoServerHelper"/></entry>
            <entry key="requestDAO"><ref bean="requestDAO"/></entry>
            <entry key="alairoCache"><ref bean="alairoCache"/></entry>
        </map>
    </property>
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="checkGracePeriodJob" />
    <!--                                 # s m h dom mon dow [y]  -->
    <property name="cronExpression" value="0 0/5 * * * ?" />
</bean>

<bean id="checkGracePeriodJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="com.synergon.sygnoserver.CheckGracePeriodJob"/>
 </bean>

流绪微梦 2024-08-05 08:33:24

我不确定这是否有效,但您可以尝试使用:

   <bean id="driverJob" .../>

而不是:

   <bean name="driverJob" .../>

I'm not sure if this will work, but you could try using:

   <bean id="driverJob" .../>

instead of:

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