官网地址

程序猿升级课

热爱开源,喜欢摸索


SpringBoot原生定时任务解析

SpringBoot原生定时任务,不需要引入任何依赖

==只要了解,几个注解就可以使用==

  • 1.在启动类上加入@EnableScheduling标签
  • 2.在定时任务方法上加入@Schedule(fixedDelay=5000)
  • 3.就是如此简单,简单的不可想象
package zebra.shjf;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class TestQuartzApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestQuartzApplication.class, args);
    }
}


@Component
public class ScheduledTasks{
    @Scheduled(fixedDelay = 5000)
    public void execute() {
        System.out.println("当前时间:" + new Date());
    }
}
posted @ 2017-02-08 11:42  chinesszz  阅读(77)  评论(0编辑  收藏  举报
ヾ(≧O≦)〃嗷~