问题
今天写了一个定时任务的demo发送到mq队列发现配置了@Scheduled注解却没有生效
sync:
time: 0 0/1 * * * ?
@Scheduled(cron = "${sync.time}")
public void execute() {
System.out.println("Execute at " + System.currentTimeMillis());
}
原因
除了配置 @Scheduled 还需要在 启动类中配置@EnableScheduling 此注解用于开启对定时任务的支持
@SpringBootApplication
@EnableScheduling
public class SyncApplication {
public static void main(String[] args) {
SpringApplication.run(SyncApplication.class, args);
}
}