本节我来介绍一下在SpringBoot中定时任务的使用以及异步调用。实现SpringBoot的定时任务非常简单,我们可以运用SpringBoot提供的注解来实现。
1、引入Maven依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
2、编写定时任务类
定义一个定时任务,我们可以使用注解**@Scheduled**。该注解提供多个参数,我来展示一下第一个参数fixedRate。
/**
* @author 小吉
* @description 定时任务
* @date 2020/6/1
*/