springTask --整合springboot 的使用

/*
* 启动类
*/

@SpringBootApplication @EnableScheduling
//开启定时器 public class PayApplication { public static void main(String[] args) { SpringApplication.run(PayApplication.class,args ); } }

定时执行的方法

@Component
public class task {
    //声明该方法是定时执行  cron参数是执行的频率
    @Scheduled(cron = "*/5 * * * * ?")
    public void print(){
        System.out.println(new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format( new Date(  ) ) );

    }
}
posted @ 2020-12-21 10:06  大姚子  阅读(50)  评论(0)    收藏  举报