Quartz 定时器任务调度配置(以及如何配置quartz启动执行一次)

1. 添加maven依赖。pom.xml 中添加jar文件



         org.quartz-scheduler
         quartz
         2.2.1


         org.quartz-scheduler
         quartz-jobs
         2.2.1

2.任务交给spring管理。web.xml 文件中引入任务调度的配置文件


        contextConfigLocation
       
            classpath*:/config/applicationContext-shiro.xml,
            classpath*:/config/applicationContext-quartz.xml
       

   

3. 配置任务调度。编写 applicationContext-quartz.xml 配置文件


    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
    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.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache.xsd">
   
   
   
            class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
       
           
       

       
            work
       

   

   
   
       
           
       

       
            0/10 * * * * ?
       

   

   
            class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
       
           
               
           

       

   

4. 编写任务类。编写定时器类

package com.xx.xxxx.ws.quarter;
public class MyJob {
    public void work()
    {
         System.out.println("work done----------");  
    }
}

触发器当中添加配置任务


            class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
       
           
               
               
           

       

   

参考:http://blog.csdn.net/juan0728juan/article/details/49025873

 

你可能感兴趣的:(Java)