spring结合quartz实现定时任务

maven依赖如下

  
        3.0.5.RELEASE  
      
  
      
          
            org.springframework  
            spring-context  
            ${springframework.version}  
          
  
          
            org.springframework  
            spring-context-support  
            ${springframework.version}  
          
  
          
            org.springframework  
            spring-tx  
            ${springframework.version}  
          
  
          
            org.springframework  
            spring-web  
            ${springframework.version}  
          
  
          
            org.quartz-scheduler  
            quartz  
            1.8.5  
          
java代码如下:

package test;

import java.util.Date;

public class Test {  
    private static int counter = 0;  
    protected void execute()  {  
        long ms = System.currentTimeMillis();  
        System.out.println("\t\t" + new Date(ms));  
        System.out.println("(" + counter++ + ")");  
    }  
}  

spring-config.xml内容如下:

   
   
  

    
         
      
        
        
      
      
      
      
          
      
        
        execute  
      
  
  
  
  
      
      
  
  
  
  
      
          
              
          
      



web.xml中配置spring

  
        contextConfigLocation  
        /WEB-INF/spring-config.xml  
      
  
      
        org.springframework.web.context.ContextLoaderListener  
     
参考文章:http://kevin19900306.iteye.com/blog/1397744


你可能感兴趣的:(Spring)