springboot 的定时任务使用

定时任务在Spring Boot中的集成

在启动类中加入开启定时任务的注解:

在SpringBoot中使用定时任务相当的简单。首先,我们在启动类中加入@EnableScheduling来开启定时任务。-------------------这是必要的

然后:

@Component
public class QuartzService {

//    每分钟启动
    @Scheduled(cron = "0 0/1 * * * ?")
    public void timerToNow(){ System.out.println("now time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); } }

一定要加入容器中。。。。

猜你喜欢

转载自www.cnblogs.com/xiaohu1218/p/9260461.html