quartz定时任务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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.itheima.health.jobs"/> <!--自动扫包,后续注入jedis到任务调度类-->
    <!--注册一个任务对象-->
    <bean class="com.itheima.health.jobs.ClearJob" id="clearJob"/>

    <!--注册JobDetail,作用是负责通过反射调用指定的Job-->
    <bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" id="deImagetail">
        <!--注入对象-->
        <property name="targetObject" ref="clearJob"/>
        <!--注入方法-->
        <property name="targetMethod" value="clearImageJob"/>
    </bean>

    <!--注册一个触发器,指定任务触发的时间,可以定义多个触发器-->
    <bean class="org.springframework.scheduling.quartz.CronTriggerFactoryBean" id="cronTrigger">
        <property name="jobDetail" ref="deImagetail"/>
        <property name="cronExpression">
            <!--crontrigger在线生成https://www.bejson.com/othertools/cron/-->
            <value>0/10 * * * * ?</value>
        </property>
    </bean>

    <!--注册一个统一的调用工厂,通过这个工厂调度任务-->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" id="scheduler">
        <property name="triggers">
            <list>
                <ref bean="cronTrigger"/>
            </list>
        </property>
    </bean>
</beans>

web.xml配置

在这里插入图片描述

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>



版权声明:本文为u011918475原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。