Spring 定时器注解 与配置文件


定时器 配置 方式 1

配置文件



	
	
		
	


java 代码

@Component
public class ZGGISJob {
	private static Logger log = Logger.getLogger(ZGGISJob.class);
	
	@Autowired
	SysAreaService sysAreaService;
	
	public void gisRun(){
		
		System.out.println("hello!");
		//SysArea record=new SysArea();
		//sysAreaService.selectByEntity(record);
	}
	
}






定时器配置方式2 


(1):修改配置 文件 如下:


[html]  view plain  copy
 print ?
  1.   
  2. <task:annotation-driven/>  
  3. <context:component-scan base-package="com.xx.controller" />  
  4. <context:component-scan base-package="com.xx.scheduler" /> span>  


[java]  view plain  copy
 print ?
  1. package com.xx.scheduler;  
  2.   
  3. import java.text.SimpleDateFormat;  
  4. import java.util.Date;  
  5.   
  6. import org.springframework.scheduling.annotation.Scheduled;  
  7. import org.springframework.stereotype.Component;  
  8. @Component  
  9. public class Job {  
  10.     public Job(){    
  11.         System.out.println("MyJob创建成功");    
  12.     }   
  13.     @Scheduled(cron = "0/1 * *  * * ? ")//每隔1秒隔行一次    
  14.     public void run(){    
  15.      System.out.println("Hello MyJob  "+  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ").format(new Date()));    
  16.     }    
  17.   
  18. }  


你可能感兴趣的:(JAVA,Spring)