SpringBoot框架实现简单定时任务
1、添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
2、在启动类上添加注解
@SpringBootApplication
@EnableScheduling // 启用定时任务
public class SpringbootQuartzApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootQuartzApplication.class, args);
}
}
3、创建定时任务
创建方式
- 方式1:cron 自定义规则
Cron表达式生成器:https://www.bejson.com/othertools/cron/