spring 定时任务

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <!-- 定义一个定时任务 -->
    <bean id="webInfoJob" class="com.tt.WebInfoJob">  <!--具体方法的执行类-->
        <property name="webInfoManager" ref="webInfoManager" />
    </bean>
    <bean id="webInfoTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                <property name="targetObject" ref="webInfoJob" />  <!--对应上面的id-->
                <property name="targetMethod" value="run" /><!--默认执行的方法-->
                <property name="concurrent" value="false" /><!--concurrent为true,则允许一个QuartzJob并发执行,否则就是顺序执行 --> 
            </bean>
        </property>
        <property name="cronExpression" value="0 */2 * * * ?" />  <!--执行时间-->
    </bean>


  <!-- 以下将bean添加到定时任务中-->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="webInfoTrigger"/>  <!--对应上面的id-->
            </list>
        </property>
       <property name="startDelay" value="30000" /><!-- 30s后启动 --> 
     <!-- 触发的规则,这里是 每天的凌晨1点触发 -->  
      <property name="cronExpression">  
          <value>0 0 1 * * ?</value>  
      </property>  
    </bean>
</beans>
 
         

 

posted @ 2015-08-25 18:17  耗子搞IT  阅读(192)  评论(0编辑  收藏  举报