1. 程式人生 > >Spirng 實現定時器

Spirng 實現定時器

一、自定義applicationContext-schedule.xml,

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
>
<bean id="sheduleAddSimpleBrowsingVolumeDayRecord" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"><ref bean="commonCountClickAction"/></property> <property name="targetMethod">
<value>addSimpleBrowsingVolumeDayRecord</value></property> </bean> <bean id="sheduleAddSimpleBrowsingVolumeDayRecordExcute" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="sheduleAddSimpleBrowsingVolumeDayRecord"/> </property> <property name="cronExpression"> <value>0 50 23,23 * * ?</value> </property> </bean> <!-- 執行列表 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <!--要部署的定時任務--> <!-- <ref local="sheduleUpdateRateExcute"/> --> <!-- <ref local="sheduleAddInterfaceDayRecordExcute"/> --> <!-- <ref local="sheduleAddSimpleBrowsingVolumeDayRecordExcute"/> --> </list> </property> </bean> </beans>
targetObject存放的是controller類目錄
targetMethod存放的是類目錄下對應的方法addSimpleBrowsingVolumeDayRecord
cronExpression定義的是在每天的那個時間段進行提交。
具體的引數,請諮詢查詢。
方法的具體實現與平常所做的修改操作沒有區別

二、將該檔案存放於webinfo下
三、在applicationContext.xml中引入
<import resource = "applicationContext-schedule.xml"/>