1、启动类启动定时任务:在启动类上面加上@EnableScheduling
即可开启定时
@EnableScheduling
@SpringBootApplication
public class TransferPass {
public static void main(String[] args) throws Exception {
SpringApplication.run(TransferPassFlowQueryStart.class, args);
}
}
2、创建定时任务实现类
@Component
public class TokenTask {
@Autowired
PropertiesReader propertiesReader;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(fixedRate = 9000000)
public void updateToken() {
propertiesReader.doRefreshToken();
//System.out.println("[" + Thread.currentThread().getName() + "]" + "现在时间:" + dateFormat.format(new Date()));
}
}