SpringBoot 定时器任务(注解方式)

package com.xxx.xxx.xxx.service.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Configuration
@EnableScheduling
public class ETask {


    Logger logger = LoggerFactory.getLogger(ETask.class);

    /**
     * 添加定时任务(每天凌晨2点执行)
     * 如果配置其他时间点的话,参考另外一篇博客:        
     * https://blog.csdn.net/qq_39415129/article/details/106114709
     *
     * @param
     * @return
     */
    @Scheduled(cron = "0 0 2 * * ?")
    private void configureTasks() {
        try {
            // 业务逻辑
        } catch (Exception e){
            logger.error("操作失败",e);
        }
    }

}

 

你可能感兴趣的:(SpringBoot 定时器任务(注解方式))