按照步骤来一一检查:
1、添加@EnableScheduling注解到入口类声明上面
/**
* 启动
*
*/
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String args[]) {
SpringApplication.run(Application.class, args);
}
}
2、创建类,添加@Component注解
@Component
public class Task {
}
3、创建方法,添加@Scheduled注解
@Scheduled(cron = "${task.cron.tradeData}")
public void getTradeData() {
}
PS:最容易出现错误的地方是在步骤三
1.此方法不能有参数
2.此方法不能有返回值
3.此类中不能包含其他带任何注解的方法
切记切记!!!!
违反任何一条,定时都不会生效!