2

在关闭tomcat时,我看到spring托管的bean被破坏了,其中是dataSource。Spring 指示quartz 关闭,并且Quartz 正在运行,配置为waitForJobsToCompleteOnShutdown = true。所以,当完成工作时,我对石英的期望低于预期,因为它没有数据源来获得连接:

2013-06-24 17:22:47,952 ERROR | schedulerFactoryBean_Worker-1 | org.quartz.core.ErrorLogger  | An error occured while marking executed job complete. job= 'DEFAULT.invoiceResponseJobDetail' 
    org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.schedulerFactoryBean': java.lang.NullPointerException
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:173) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3788) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3760) ~[quartz-2.1.7.jar:na]
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.triggeredJobComplete(JobStoreSupport.java:3000) ~[quartz-2.1.7.jar:na]
    at org.quartz.core.QuartzScheduler.notifyJobStoreJobComplete(QuartzScheduler.java:1753) ~[quartz-2.1.7.jar:na]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:281) ~[quartz-2.1.7.jar:na]
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) ~[quartz-2.1.7.jar:na]
    Caused by: java.lang.NullPointerException: null
    at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:165) ~[quartz-2.1.7.jar:na]
    ... 6 common frames omitted

数据源配置:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/springDataSource" />
    <property name="lookupOnStartup" value="true" />
    <property name="proxyInterface" value="javax.sql.DataSource" />
</bean>

弹簧石英配置:

<bean id="schedulerFactoryBean"
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean" depends-on="dataSource">

    <property name="waitForJobsToCompleteOnShutdown">
        <value>true</value>
    </property>

    <property name="triggers">
        <list>
            <ref bean="accountRequestJobDetailTrigger" />
        </list>
    </property>

    <property name="schedulerContextAsMap">
        <map>
            <entry key="accountRequestJob" value-ref="accountRequestJob" />
        </map>
    </property>

    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreCMT</prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
            </prop>
            <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.scheduler.instanceName">SAPClusteredScheduler</prop>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
        </props>
    </property>

    <property name="dataSource" ref="dataSource" />
</bean>

怎么样,我可以在 spring bean 被销毁之前让这种工作清理发生吗?

4

1 回答 1

2

我相信你可能会使用SmartLifeCycle. 让您的 bean/类实现它并确保getPhase()返回Integer.MIN_VALUE

此答案中还提到:https ://stackoverflow.com/a/5892829/248082

于 2013-06-24T13:12:28.037 回答