import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ScheduledService {
private static final Logger log = LoggerFactory.getLogger(ScheduledService.class);
/**
* 每天凌晨执行一次
*/
@Scheduled(cron = "0 0 0 * * ?")
public void scheduled(){
}
}
转载于:https://blog.51cto.com/7218743/2383099
本文介绍了如何在Spring框架中使用@Scheduled注解来配置定时任务,通过cron表达式设置任务执行的时间,如每天凌晨执行一次。展示了如何创建一个ScheduledService组件并实现定时任务的方法。

被折叠的 条评论
为什么被折叠?



