Spring定时器
新建一个用于执行定时器的类 TimerTask ,新建准备用于执行同步任务的方法 startTimerJob
public void startTimerJob(){ StaticServiceImpl staticService = (StaticServiceImpl)SpringInit.getApplicationContext().getBean("staticServiceImpl"); logger.debug("Start Timer Job"); System.out.println("Start Timer Job"); logger.debug("sync " + staticService.syncSalesFromSqlServer() + " datas"); }
StaticServiceImpl 是用标签注入的类, 在这里用SPring的工厂取得。
配置定时器
<bean id="timerTask" class="com.ceair.muss.common.timer.TimerTask"></bean> <bean id="ZntaskTopSaleJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="timerTask"></property> <property name="targetMethod" value="startTimerJob"></property> </bean> <bean id="zntaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="ZntaskTopSaleJobDetail"/> </property> <property name="cronExpression"> <value>0 0 1 * * ?</value> </property> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="zntaskTrigger"/> </list> </property> </bean>
OK 成功运行。
具体配置参考
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14