@Component
public class TimerService {
@Scheduled(cron = "0/5 * * * * ?")
public void schTest1() {
Date date = new Date();
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sim.format(date);
System.out.println("这是spring定时器,每5秒执行一次,当前时间:" + dateStr);
}
}
cron表达式在线生成器: http://cron.qqe2.com/