在启动类上加上 @EnableScheduling 注解
package com.nanfan.core.utils;
import com.nanfan.core.service.impl.OrdersServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* @Author wcd
* @Version 1.0v
* @Description :定时器工具类
* @date 2019/8/28/11:29
*/
@Component
public class TimerUtil {
@Autowired
private OrdersServiceImpl ordersService;
//每天00点:01分执行
@PostConstruct//跟随系统运行
@Scheduled(cron = "0 01 00 ? * *")
public void timedRefresh() {
//每天00点:01分刷新订单
ordersService.Refresh();
}
}