说是集成,其实不对,因为springboot本来就自带定时任务。只需要configuration里面加上注解@EnableScheduling就表示启动。
具体的实现方法里面用@Scheduled(cron = "0/2 * * * * ?")
即可。
@SpringBootApplication
@EnableScheduling
public class AccessingDataMysqlApplication {
public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(AccessingDataMysqlApplication.class, args);
}
@Scheduled(cron = "0/2 * * * * ?")
public void dd(){
System.out.println(Instant.now());
}
}