part 1:
@Component
public class Scheduled {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(cron = "0 0/30 * * * ? ") //每隔30分钟执行一次
public void timerRate() {
System.out.println(dateFormat.format(new Date()));
//编写 需要定时执行的业务就OK了
aaa(User);
}
}
part 2:
在SpringBootApplication 类,上加注解@EnableScheduling
@SpringBootApplication
@EnableScheduling
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootScheduledApplication.class, args);
}
}
完成以上两个步骤,springboot 定时任务OK了!