创建定时任务类 @Component public class ScheduledDemo { /* * 定时任务 * @Scheduled 设置定时任务 * cron属性:cron表达式,时间的字符串表达式 * 秒 分 时 天 月 年 * */ @Scheduled(cron = "0/2 * * * * ?") public void scheduledMethod(){ System.out.println("定时器触发:"+new Date()); } } 在项目启动类上面加@EnableScheduling的注解 @SpringBootApplication @EnableScheduling public class DistributionApplication { public static void main(String[] args) { SpringApplication.run(DistributionApplication.class, args); } }
springboot定时任务
最新推荐文章于 2024-08-22 13:20:24 发布