Spring Boot 学习15--定时任务的使用

来源:互联网 发布:河源市民网络问政平台 编辑:程序博客网 时间:2024/06/15 19:09

本文介绍在 Spring Boot 中如何使用定时任务,使用非常简单,就不做过多说明了。

com.kfit.base.scheduling.SchedulingConfig:

package com.kfit.base.scheduling;

 

import org.springframework.context.annotation.Configuration;

import org.springframework.scheduling.annotation.EnableScheduling;

import org.springframework.scheduling.annotation.Scheduled;

 

/**

 * 定时任务

 * @author Administrator

 *

 */

@Configuration

@EnableScheduling

publicclass SchedulingConfig {

   

    @Scheduled(cron = "0/20 * * * * ?"// 20秒执行一次

    publicvoid scheduler() {

        System.out.println(">>>>>>>>> SchedulingConfig.scheduler()");

    }

}

0 0
原创粉丝点击