zoukankan      html  css  js  c++  java
  • 通过maven添加quartz

    pom.xml中相关dependency信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>3.1.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
                <version>3.1.1.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>3.1.1.RELEASE</version>
            </dependency>
            <dependency>  
                <groupId>org.springframework</groupId>  
                <artifactId>spring-web</artifactId>  
                <version>3.0.5.RELEASE</version>  
            </dependency
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz</artifactId>
                <version>1.8.5</version>
            </dependency>    

    quartzJob.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <!-- 定义目标bean和bean中的方法 -->  
        <!-- =====================日常任务job========================== -->
        <bean id="DailyTaskQtzJob" class="com.test.quartz.DailyTaskJob">
        </bean>  
        <bean id="DailyTaskQtzJobMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
            <property name="targetObject">  
                <ref bean="DailyTaskQtzJob"/>  
            </property>  
            <property name="targetMethod">  <!-- 要执行的方法名称 -->  
                <value>execute</value>  
            </property>  
        </bean
       
        <!-- ======================== 调度触发器 ======================== -->  
      <bean id="DailyTaskCronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">  
            <property name="jobDetail" ref="DailyTaskQtzJobMethod"></property>  
            <!-- 每天下午16:30触发   -->
            <property name="cronExpression" value="0 30 16 ? * *"></property>
        </bean>  
       
        <!-- ======================== 调度工厂 ======================== -->  
        <bean id="SpringJobSchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
            <property name="triggers">  
                <list>   
                    <ref bean="DailyTaskCronTriggerBean"/> 
                </list>  
            </property>  
        </bean>  

    DailyTaskJob.java

    1
    2
    3
    4
    5
    6
    7
    8
    package com.test.quartz;
     
    public class DailyTaskJob { 
     
        protected void execute() {
             //执行任务
        }
    }

    最后在web.xml中添加quartzJob.xml

    1
    2
    3
    4
    5
    6
    7
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            WEB-INF/beans.xml
            WEB-INF/quartz/quartzJob.xml
        </param-value>
    </context-param>

    OK,这就配好啦,记录一下,防止以后忘了。

  • 相关阅读:
    SrsDataConnector The SQL Server Reporting Services account is a local user and is not supported.
    Marketing with Microsoft Dynamics CRM IDEA CONFERENCE
    Discuz!X 系列 HTTP_X_FORWARDED_FOR 绕过限制进行密码爆破
    PHPCMS v9.5.6 通杀getshell(前台)
    PHPCMS v9.5.8-设计缺陷可重置前台任意用户密码
    PHPCMS v9.6.0 任意用户密码重置
    PHPCMS V9 任意文件下载(Windows)
    Joomla!3.7.0 Core SQL注入漏洞动态调试草稿
    利用FOFA搜索WatchGuard防火墙
    如何删除Windows休眠文件(hiberfil.sys)
  • 原文地址:https://www.cnblogs.com/jgig11/p/4383302.html
Copyright © 2011-2022 走看看