步驟1:
在主類加註解開啓定時任務
@EnableCaching
2.方法加註解,寫cron表達式
不會也沒關係,網上有生成cron表達式的,
@Scheduled(cron = "0/5 * * * * ?")
演示實例
@Scheduled(cron = "0/5 * * * * ?")
public void taskQuartz(){
System.out.println("執行定時任務打印");
}
結果:
這裏是每五秒打印一次,大功告成了。