1开启定时任务功能
@SpringBootApplication
//开启定时任务功能
@EnableScheduling
public class SpringboottaskApplication {
public static void main(String[] args) {
SpringApplication.run(SpringboottaskApplication.class, args);
}
}
2设定具体任务作为定时任务
@Component
public class MyBean {
@Scheduled(cron = "0/1 * * * * ?")
public void print() {
System.out.println("spring task run....");
}
}
浙公网安备 33010602011771号