springboot 开启 定时任务

一、启动类

启动类添加注解

@EnableScheduling

二、创建定时任务类

package com.wt.lease.web.admin.schedule;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTasks {

    @Scheduled(cron = "* * * * * *")
    public void test(){
        // 任务
        System.out.println(new Date());
    }
}

三、cron

 *    *   *   *   *    *

秒 分 时 日 月 星期

posted @ 2025-05-14 21:37  市丸银  阅读(27)  评论(0)    收藏  举报