SpringBoot定时任务Scheduled

我们在开发中有时会使用到定时任务,此时使用Scheduled注解能很快实现我们的需求

在我们需要定时执行的类上添加注解

//使用cron属性可按照指定时间执行,本例指的是每10分钟执行一次;
@Scheduled(cron = “0 0/10 * * * ?”) 

然后在启动类上添加@EnableScheduling注解。

@EnableScheduling 注解,它的作用是发现注解@Scheduled的任务并由后台执行。没有它的话将无法执行定时任务。

还有其他方法,请自行百度

猜你喜欢

转载自blog.csdn.net/rui15111/article/details/80972854