1泌参、pom包配置
pom包里面只需要引入springboot starter包即可
? ? ? ? ? ? org.springframework.boot? ? ? ? spring-boot-starter? ? ? ? ? ? ? ? org.springframework.boot? ? ? ? spring-boot-starter-test? ? ? ? test? ? ? ? ? ? ? ? org.springframework.boot? ? ? ? spring-boot-devtools? ? ? ? true? ?
2脆淹、啟動(dòng)類啟用定時(shí)
在啟動(dòng)類上面加上@EnableScheduling即可開啟定時(shí)
@SpringBootApplication@EnableSchedulingpublicclassApplication{publicstaticvoidmain(String[] args){? ? ? ? SpringApplication.run(Application.class, args);? ? }}
3、創(chuàng)建定時(shí)任務(wù)實(shí)現(xiàn)類
@ComponentpublicclassSchedulerTask{privateintcount=0;@Scheduled(cron="*/6 * * * * ?")privatevoidprocess(){? ? ? ? System.out.println("this is scheduler task runing? "+(count++));? ? }}
fe7d59c7257408537911a79d343c6e3.png
3沽一、cron表達(dá)式
常用: 秒盖溺、分、時(shí)铣缠、日烘嘱、月、年
0 0 8,16,18 * * ? 每天上午8點(diǎn)蝗蛙,下午4點(diǎn)蝇庭,6點(diǎn)
0 0 13 * * ? 每天下午1點(diǎn)觸發(fā)
0 0/7 0 * * ? 每7分鐘執(zhí)行一次
*/5 * * * * ? 每隔5秒執(zhí)行一次
更多表達(dá)式請(qǐng)見:https://blog.csdn.net/weixin_40426638/article/details/78959972