参考文章
https://zhuanlan.zhihu.com/p/95813468
https://www.cnblogs.com/oliverreal/p/10652380.html
cron表达式
https://blog.csdn.net/qq_39019865/article/details/79709389
定时任务实例
@EnableScheduling//开启定时任务
@EnableTransactionManagement//开启事务
@MapperScan("com.my.learn.mapper")
@SpringBootApplication
@EnableAspectJAutoProxy //开启spring对注解aop的支持
public class MyBatisLearnApplication {
public static void main(String[] args) {
SpringApplication.run(MyBatisLearnApplication.class);
}
}
//@PropertySource("classpath:/xxxx.properties") 可以读取指定文件
@Component
public class FixedPrintTask {
@Scheduled(cron = "${task.rule}")
public void execute() {
System.out.println("schedule execute " + System.currentTimeMillis());
}
@Scheduled(cron = "0/5 * * * * ?")
public void execute2() {
System.out.println("schedule execute 2 " + System.currentTimeMillis());
}
}
application.yml文件
task:
rule: 0/5 * * * * ?
cron规则