2011-11-02 82 views
1

配置:石英:每天運行一次任務,不按repeatInterval

<bean id="simpleTrigger" 
     class="org.springframework.scheduling.quartz.SimpleTriggerBean"> 

     <property name="jobDetail" ref="runMeJob" /> 
     <property name="repeatInterval" value="5000" /> 
     <property name="startDelay" value="1000" /> 

    </bean> 

    <!-- Cron Trigger --> 
    <bean id="cronTrigger" 
     class="org.springframework.scheduling.quartz.CronTriggerBean"> 

     <property name="jobDetail" ref="runMeJob" /> 
     <property name="cronExpression" value="0 45 16 ? * MON-FRI" /> 

    </bean> 

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
     <property name="jobDetails"> 
      <list> 
      <ref bean="runMeJob" /> 
      </list> 
     </property> 

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

我需要在每個工作日一次16:45運行任務。
simpleTrigger警告如果我不使用repeatInterval,由於它不能爲0,但我不需要它,因爲需要我的任務每天執行一次。

回答

2

爲什麼你連都有 simpleTrigger?您的cronTrigger應該足以在每個工作日16:45運行任務。

<!-- Cron Trigger --> 
<bean id="cronTrigger" 
    class="org.springframework.scheduling.quartz.CronTriggerBean"> 

    <property name="jobDetail" ref="runMeJob" /> 
    <property name="cronExpression" value="0 45 16 ? * MON-FRI" /> 

</bean> 

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
    <property name="jobDetails"> 
     <list> 
     <ref bean="runMeJob" /> 
     </list> 
    </property> 

    <property name="triggers"> 
     <list> 
     <ref bean="cronTrigger" /> <!-- use cronTrigger instead of simpleTrigger --> 
     </list> 
    </property> 
</bean> 
+0

StriplingWarrior,謝謝你來看,我是unattentive,但奇怪的,這種表達不仍然工作:0 45 16? * MON-FRI,這個表達方式正常:0/5 * * * *? – sergionni