Spring Boot定时任务的使用实例代码
SpringBoot中配置定时任务极其简单......下面看下实例代码:
importorg.springframework.context.annotation.Configuration;
importorg.springframework.scheduling.annotation.EnableScheduling;
importorg.springframework.scheduling.annotation.Scheduled;
importjava.text.SimpleDateFormat;
importjava.util.Date;
/**
*Createdbywinner_0715on2017/4/18.
*/
@Configuration
@EnableScheduling
publicclassSchedulingConfig{
//每5秒执行一次
@Scheduled(cron="0/5****?")
publicvoidscheduler(){
System.out.println("SchedulingConfig.scheduler()"+
newSimpleDateFormat("yyyy-MM-ddHH:mm:ss").format(newDate()));
}
}
以上所述是小编给大家介绍的SpringBoot定时任务的使用实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!