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"/>

猜你喜欢

转载自blog.csdn.net/weixin_42932323/article/details/82345962