• 在springboot启动类上开启定时任务开关@EnableScheduling
  • 新建一个要执行的任务

@Scheduled(cron = "0/5 * * * * ?")
表示要执行的频率

@Scheduled(cron = "0/5 * * * * ?")
    public void print(){
        System.out.println("task>>>>>>>>>>>>>>>>>");
    }

  • application.yml 文件中可以配置相关属性 如(前缀、连接池大小等)
spring:
  task:
    scheduling:
      thread-name-prefix: spring_task