版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ITwuyang/article/details/77506337
1.创建java类SchedulingConfig
2.配置@Configuration注解
3.打开任务调度@EnableScheduling
4.方法名上写调度周期配置@Scheduled(cron = “0/20 * * * * ?”) // 每20秒执行一次
具体代码如下
package cn.wuyang.springboot.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
/**
* 定时任务
* 1.配置@Configuration注解
* 2.打开任务调度@EnableScheduling
* 3.方法名上写调度周期配置@Scheduled(cron = "0/20 * * * * ?") // 每20秒执行一次
* @author wuyang
*
*/
@Configuration
@EnableScheduling
public class SchedulingConfig {
@Scheduled(cron = "0/20 * * * * ?") // 每20秒执行一次
public void SchedulingTest() {
System.out.println(">>>>>>>>> SchedulingConfig.scheduler()");
}
}