quarz定时任务

来源:互联网 发布:ajax跨域请求不是json 编辑:程序博客网 时间:2024/06/07 21:39
  <!--定时任务 maven依赖 -->
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>

        </dependency>


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       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-4.0.xsd
                    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    <!-- 自定义要执行的job -->
    <bean id="myJob" class="com.mall.quarz.MyJob"></bean>
   

    <!-- scheduler调度器 -->
    <bean id="startQuertz" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" autowire="no">
        <property name="triggers">
            <list>
                <ref bean="myJobTrigger"/>
            </list>
        </property>
    
    </bean>
    
    <!-- 触发器 -->
    <bean id="myJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail">
            <ref bean="myJobDetail"/>        
        </property>
        <property name="cronExpression">
            <value>1/3 * * * * ? *</value>
        </property>
    </bean>
    
    <!-- 任务详情 -->
    <bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject">
            <ref bean="myJob"/>
        </property>
        <property name="targetMethod">
            <value>doJob</value>
        </property>
    
    </bean>
    








</beans>



原创粉丝点击