Java SpringBoot 定时器注解版的使用@Scheduled(cron = "0 0 0 * * * ")
添加注解@EnableScheduling开启定时器总开关
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@Configuration
@EnableScheduling //开启定时任务
public class Test {
// 定时每天一点 格式: cron = [秒] [分] [小时] [日] [月] [周] [年] 在线Cron表达式生产器 https://qqe2.com/cron
@Scheduled(cron = "0 0 1 * * ?")
private void Test_Tasks() {
System.out.println("输出信息");
}
}