1.主程序入口类上加入注解
@EnableScheduling //开启基于注解的定时任务
2.新建测试类
package com.example.demo.service.impl;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class TestShedualServiceImpl {
@Scheduled(cron = "0/5 * * * * ? ")
public void TestSchedul(){
System.out.println("5秒运行一次");
}
}
3.启动观察结果