Spring Task是一个定时任务框架,可以定时执行某段任务代码。
案例举例
注意:只要是需要定时处理的场景都可以使用Spring Task
1入职纪念日为用户发送通知
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/e00bc7be3d1f4a14996b47d250cc6af9.png)
2银行贷款每月还款提醒
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/968634fef44d467a98078ae8c2defe1d.png)
Spring Task的使用步骤
1)导入maven坐标
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
2)启动类添加注解 @EnableScheduling 开启任务调度
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/ae0b9de4aa5a43d18b1378311d1cdf32.png)
3)自定义定时任务类
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/3f03ea2ae4044a4788f8aeb42fd7d6cd.png)