springboot 的定时任务使用
定时任务在Spring Boot中的集成
在启动类中加入开启定时任务的注解:
在SpringBoot中使用定时任务相当的简单。首先,我们在启动类中加入@EnableScheduling来开启定时任务。-------------------这是必要的
然后:
@Component
public class QuartzService {
//    每分钟启动
    @Scheduled(cron = "0 0/1 * * * ?")
    public void timerToNow(){
        System.out.println("now time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }
}一定要加入容器中。。。。
 
                     
                    
                 
                    
                
 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号