0
点赞
收藏
分享

微信扫一扫

@Scheduled 实现定时任务

丹柯yx 2022-02-10 阅读 112

@Scheduled注解实现定时任务

一、创建一个Springboot项目在启动类里加上@EnableScheduling

二、在写的定时任务的类上加上@Component把该类交由springboot管理

三、在需要做定时操作的方法上加上@Scheduled(cron = " ")注解

四、cron表达式(定时任务通过cron表达式控制定时时间)

1、符号示意

2、字段允许字符

(1)秒:0-59 , - * /

(2)、分:0-59 , - * /

(3)、时:0-23 , - * /

(4)、天(月):1-31 , - * / ? L W C

(5)、月:1-12 , - * /

(6)、天(周):MON-SAT , - * / ? L C

(7)、年:留空 2020-2099 , - * /

四、启动项目即可

举报

相关推荐

0 条评论