码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot功能持续更新

时间:2018-04-06 20:21:10      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:app   rgs   sch   row   gap   format   date   配置   run   

【定时任务】
1.启动总开关
@EnableScheduling加在@SpringBootApplication注解的start入口处,表示启动总开关

@SpringBootApplication
@EnableScheduling
public class start {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(start.class, args);
    }
}

2.再单独给方法加配置
@Scheduled(cron="0/5 * * * * ?")每5秒打印当前时间

    @Scheduled(cron="0/5 * * * * ?")
    public void reportCurrentTime() {
        log.info("The time is now {}", dateFormat.format(new Date()));
    }

技术分享图片

备注:cron表达式,秒分时天等等,具体用到可以再百度

SpringBoot功能持续更新

标签:app   rgs   sch   row   gap   format   date   配置   run   

原文地址:https://www.cnblogs.com/likailun/p/8728515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!