spring boot启动定时任务
作者:互联网
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.启动观察结果
标签:Scheduled,Service,spring,boot,springframework,import,org,定时,public 来源: https://blog.csdn.net/weixin_43785508/article/details/122287968