0.启动类中增加@EnableScheduling注解
@EnableScheduling
@SpringBootApplication
public class Application {
public static void main(String[] args) {
Application.run(Application.class, args);
}
}
1.定义调度类
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class DeviceInfoSyncJob {
@Scheduled(cron = "0/2 * * * * ?")
private void doJob() {
log.info("任务执行~");
}
@Scheduled(cron = "${job.device-info-sync.cron}")
private void doJob1() {
log.info("任务1执行~");
}
}