本人暫時用到的實現定時任務的方式有2種
一、註解方式實現,簡單方便
- public class TmallPriceStoreChangeFailedGetJob {
- public void work() {
- //具體方法實現
- }
- }
- <import resource="application_tmallPriceStorceChangeFailed"/>
3.application_tmallPriceStorceChangeFailed_task.xml文件按照以下寫法
- <!-- quartz job config begin -->
- <bean id="tmallPriceStoreChangeFailedGetJob" class="com.shopin.third.job.TmallPriceStoreChangeFailedGetJob" />
- <bean id="getTmallPriceStroeChangeFailed"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
- <property name="targetObject">
- <ref bean="tmallPriceStoreChangeFailedGetJob" />
- </property>
- <property name="targetMethod">
- <value>work</value>
- </property>
- </bean>
- <bean id="getTmallPriceStroeChangeFailedTask" class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail">
- <ref bean="getTmallPriceStroeChangeFailed" />
- </property>
- <!-- cron表達式 -->
- <property name="cronExpression">
- <value>0 30 09 * * ?</value><!--每天9點30執行一次 -->
- </property>
- </bean>
- <!-- quertz 啓動配置 -->
- <bean id="startTmallQuertz"class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <ref bean="getTmallPriceStroeChangeFailedTask" />
- </list>
- </property>
- </bean>