废话不说直接上代码:
controller:
@Controller
@EnableScheduling
public class SchedulingUtil {
@Autowired
private ceshi ceshi;
private static final SimpleDateFormat date=new SimpleDateFormat("HH:mm:ss");
@Scheduled(cron = "0/10 * * * * ?")
public void testTasks(){
ceshi.ceshi();
System.out.println("定时任务执行:"+date.format(new Date()));
}
}
业务层service:
@Service
public class ceshi{
public void ceshi(){
System.out.println(11111);
//自己的业务
}
}
springboot项目注意**@EnableScheduling**注解没这个注解不能成功