SpringBoot启动后启动一个定时任务

SpringBoot启动后启动一个定时任务

  1. 创建一个类实现CommandLineRunner接口
  2. 实现 run 方法
  3. 方法中实现定时任务的逻辑
  4. 记得 @Component 注解
@Component
public class Xxxxx implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        // method
    }

}
posted @ 2023-12-29 12:50  20231012  阅读(47)  评论(0)    收藏  举报