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

Spring Boot定时任务的使用

时间:2017-04-19 00:35:13      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:ann   imp   gconf   mat   style   color   log   simple   spring   

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定时任务的使用

标签:ann   imp   gconf   mat   style   color   log   simple   spring   

原文地址:http://www.cnblogs.com/winner-0715/p/6731219.html

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