2008-12-05 133 views
0

我已經聲明瞭以下豆在我的Spring配置方法,調用的Spring bean

<bean id="templateCacheClearingTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"> 
    <property name="delay" value="5000" /> 
    <property name="period" value="5000" /> 

    <property name="timerTask"> 
     <bean class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean"> 
      <property name="targetObject" ref="templateMailService" /> 
      <property name="targetMethod" value="clearCache" /> 
     </bean> 
    </property> 
</bean> 

這應該引起templateMailService bean的clearCache()方法每隔5000毫秒調用,但沒有什麼似乎發生。我錯過了什麼嗎?

乾杯, 唐

回答

5

我想你需要:

<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean"> 
    <property name="scheduledTimerTasks"> 
    <list> 
     <ref bean="templateCacheClearingTask"/> 
    </list> 
    </property> 
</bean> 

除了你已經擁有。