一、引入定时器的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
二、自定义一个任务类
@Component
public class MyTask {
@Scheduled(cron = "0/10 * * * * ?")
public void task(){
System.out.println("`````````````");
}
}
三、在主启动类上添加注解@EnableScheduling
@SpringBootApplication
@EnableScheduling
public class SpringbootMybatisplusApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootMybatisplusApplication.class, args);
}
}