Spring Boot实践记录

SpringBoot原生定时任务解析

2017-02-08  本文已影响48人  Chinesszz

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

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

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());
    }
}
上一篇 下一篇

猜你喜欢

热点阅读