2014-02-24 53 views
3

我一直在尋找幾天來簡單地實現Spring批處理程序與調度程序(Quartz),但沒有運氣!一切,我把我的手放在不工作或貶值的樣本,我的應用程序應該提供設置作業燒成時間動態(從數據庫中檢索)Spring 4 + Spring Batch + Quartz 2.2.x教程

+0

當數據庫中的作業啓動時間發生改變時,你應該怎麼做?石英作業被初始化一次並相應觸發。 –

+0

是的,但對我來說,作業觸發時間可以在運行期間更改... – askory

+0

我認爲你需要的是將其標記爲「每分鐘」。每分鐘,你都會運行這個任務。第一行從數據庫中獲取實際的cron表達式,第二行像在當前時間檢查cron表達式。在if語句中,運行實際的代碼。 –

回答

0

嘗試添加以下代碼彈簧quartz.xml文件

<!--testAlerts cron trigger --> 
<bean id="testAlertsTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
    <property name="name" value="testAlertsTrigger" /> 
    <property name="jobDetail" ref="testAlertsJobDetail" /> 
    <property name="cronExpression" value="0 0 4 * * ?" /> 
</bean> 

<!-- scheduler --> 
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="transactionManager" ref="hbnTransactionManager" /> 
    <property name="triggers"> 
     <list> 
       <ref bean="testAlertsTrigger" /> 
     </list> 
    </property> 
    <property name="schedulerContextAsMap"> 
     <map> 
      <entry key="commandDispatcher" value-ref="commandDispatcher" /> 
     </map> 
    </property> 
    <property name="autoStartup" value="${QUARTZ.org.quartz.autoStartup}" /> 
    <property name="overwriteExistingJobs" value="${QUARTZ.org.quartz.overwriteExistingJobs}" /> 
    <property name="quartzProperties"> 
     <props> 
      <prop key="org.quartz.scheduler.instanceId">${QUARTZ.org.quartz.scheduler.instanceId}</prop> 
      <prop key="org.quartz.scheduler.instanceName">${QUARTZ.org.quartz.scheduler.instanceName}</prop> 
      <prop key="org.quartz.threadPool.threadCount">${QUARTZ.org.quartz.threadPool.threadCount}</prop> 
      <prop key="org.quartz.jobStore.class">${QUARTZ.org.quartz.jobStore.class}</prop> 
      <prop key="org.quartz.jobStore.isClustered">${QUARTZ.org.quartz.jobStore.isClustered}</prop> 
      <prop key="org.quartz.jobStore.clusterCheckinInterval">${QUARTZ.org.quartz.jobStore.clusterCheckinInterval}</prop> 
     </props> 
    </property> 
</bean>