1.@Scheduled创建定时任务,在springBoot主类中加入@EnableScheduling注解启用定时任务的配置,备注:不支持集群,集群可以使用xxl-job

2.首先创建一个task包和一个类,这个类中创建一个方法来进行定时任务

spring boot---创建定时任务

 

 3.需要在启动类中启动我们的定时任务

spring boot---创建定时任务

 

 4.启动之后我们来看看效果,如果是需要用正则进行匹配,可以在这里进行你需要的表达式https://www.bejson.com/othertools/cron

spring boot---创建定时任务

 

 

package demo.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

//把普通pojo实例化到spring容器中,相当于配置文件中的
//<bean +System.currentTimeMillis());
}
}



 

相关文章:

  • 2021-12-11
  • 2021-08-07
  • 2022-12-23
  • 2021-11-12
猜你喜欢
  • 2021-09-17
  • 2022-03-09
  • 2022-12-23
  • 2021-07-07
  • 2021-08-17
相关资源
相似解决方案