springboot集成schedule定时任务

说是集成,其实不对,因为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());
    }
}
发布了422 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/enthan809882/article/details/104059912