springboot整合定时任务(注解模式)

package com.mt.vuedemo.task;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**

  • @author zjt

  • @version 1.0

  • @date 2020/9/14 8:50
    */
    @Configuration
    @EnableScheduling
    public class TestTask {

    @Scheduled(cron = “0/5 * * * * ?”)
    public void UpdateData() {
    System.out.println(“testApp”);
    }
    }

关键注解:
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务

猜你喜欢

转载自blog.csdn.net/qq_41608559/article/details/108572119
今日推荐