• SpringQtz 时间任务调度


    1、配置所需要maven jar包

    <!-- 任务调度需要的jar包-->
    <dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>1.8.5</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.2.4.RELEASE</version>
    </dependency>

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>3.2.4.RELEASE</version>
    </dependency>

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.2.4.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.2.4.RELEASE</version>
    </dependency>
    <!-- 任务调度需要的jar包-->

    2、配置文件spring-timer.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <!-- 配置调度程序quartz ,其中配置JobDetail有两种方式-->
    <!--方式一:使用JobDetailBean,任务类必须实现Job接口 -->
    <!-- <bean id="myjob" class="org.springframework.scheduling.quartz.JobDetailBean"> -->
    <!-- <property name="name" value="exampleJob"></property> -->
    <!-- <property name="jobClass" value="com.zbb.cn.filter.SpringQtz"></property> -->
    <!-- <property name="jobDataAsMap"> -->
    <!-- <map> -->
    <!-- <entry key="service"> -->
    <!-- <value>simple is the beat</value> -->
    <!-- </entry> -->
    <!-- </map> -->
    <!-- </property> -->
    <!-- </bean> -->
    <!--运行时请将方式一注释掉! -->
    <!--
    方式二:使用MethodInvokingJobDetailFactoryBean,任务类可以不实现Job接口,通过targetMethod指定调用方法
    -->
    <!-- 定义目标bean和bean中的方法 -->
    <bean id="SpringQtzJob" class="com.cc.hkjc.controller.backstage.interceptor.SpringQtz">

    </bean>

    <bean id="SpringQtzJobMethod"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject">
    <ref bean="SpringQtzJob" />
    </property>
    <property name="targetMethod"> <!-- 要执行的方法名称 -->
    <value>execute</value>
    </property>
    </bean>

    <!-- ======================== 调度触发器 ======================== -->
    <bean id="CronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="SpringQtzJobMethod"></property>
    <!-- <property name="cronExpression" value="0/5 * * * * ?"></property> -->
    <property name="cronExpression" value="0 0 10 * * ?"></property> <!-- 每天晚上十点触发 -->
    </bean>

    <!-- ======================== 调度工厂 ======================== -->
    <bean id="SpringJobSchedulerFactoryBean"
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
    <list>
    <ref bean="CronTriggerBean" />
    </list>
    </property>
    </bean>

    </beans>

    package com.cc.hkjc.controller.backstage.interceptor;

    import java.util.Calendar;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import javax.annotation.Resource;

    import org.apache.cxf.common.util.StringUtils;

    import com.cc.hkjc.domain.HcNum;
    import com.cc.hkjc.domain.Zstj;
    import com.cc.hkjc.service.PhoneService;
    import com.cc.hkjc.service.ZstjService;

    public class SpringQtz {
    private static int count=0;
    @Resource
    private ZstjService zstjService;

    @Resource
    private PhoneService phoneService;

    public void execute() {
      
    }
    }

    4、在web.xml配置spring-timer.xml

  • 相关阅读:
    【科技】扩展Lucas随想
    【NOI 2018】屠龙勇士(扩欧)
    【NOI 2018】冒泡排序(组合数学)
    【NOI 2018】归程(Kruskal重构树)
    【APIO 2018】铁人两项(圆方树)
    【科技】KD-tree随想
    UOJ#207. 共价大爷游长沙 LCT
    UOJ#23. 【UR #1】跳蚤国王下江南 仙人掌 Tarjan 点双 圆方树 点分治 多项式 FFT
    UOJ#33. 【UR #2】树上GCD 点分治 莫比乌斯反演
    UOJ#191. 【集训队互测2016】Unknown 点分治 分治 整体二分 凸包 计算几何
  • 原文地址:https://www.cnblogs.com/swite/p/5734271.html
Copyright © 2020-2023  润新知