超简单实现springboot项目中的定时任务

1、在主启动类上加入  @EnableScheduling 注解;

2、新建类如下:

package com.hauto.order.service.express.impl;

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

/**
 * @Desc:
 * @Author: gongcheng
 * @Date: 2020/06/04  19:49
 **/
@Component
public class TimerSecude {
    @Scheduled(cron = "0/5 * * * * ?")
    public void testTimer(){
        System.out.println("=========================this is ding shi ren wu ");
    }

}

启动即可实现定时任务

你可能感兴趣的:(springBoot)