1.开启定时任务功能
2.编写定时任务
package com.fdw.springbootstudy.service;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class ScheduledService {
//在一个特定的时间执行
//cron表达式
//秒 分 时 日 月 周几~
/*
cron = "0 15 10 * * ?" 每天的10点15分执行一次
cron = "0 0/5 10,18 * * ?" 每天的10点和18点,每隔5分钟执行一次
*/
@Scheduled(cron = "0 15 10 * * ?")
public void hello(){
System.out.println("hello程序已经被执行了");
}
}