Spring Boot定时任务的使用实例代码

Spring Boot中配置定时任务极其简单......下面看下实例代码:

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * Created by winner_0715 on 2017/4/18.
 */
@Configuration
@EnableScheduling
public class SchedulingConfig {
  // 每5秒执行一次
  @Scheduled(cron = "0/5 * * * * ?")
  public void scheduler() {
    System.out.println("SchedulingConfig.scheduler()" + 
        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
  }
}

以上所述是小编给大家介绍的Spring Boot定时任务的使用实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

以上是来客网为你收集整理的Spring Boot定时任务的使用实例代码全部内容,希望文章能够帮你解决Spring Boot定时任务的使用实例代码所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。