@EnableScheduling主類中加入註釋
@Component public class ScheduledTest { //fixedRate任務兩次執行時間間隔是任務的開始點,而 fixedDelay 的間隔是前次任務的結束與下次任務的開始。 @Scheduled(fixedRate = 5000) public void scheduledDemo(){ System.out.println("scheduled - fixedRate - print time every 5 seconds:{}"+System.currentTimeMillis() ); } //cron表達式 @Scheduled(cron = "0 0/1 * * * ?") public void runa(){ System.out.println("當前時間"+System.currentTimeMillis()); } }