@Component
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Transactional
public class AutoTask {
/**
* 每天凌晨1点执行一次
*/
@Scheduled(cron = "0 0 1 * * ?")
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void customizeClass(){
//业务逻辑代码
}
springboot中通过注解定义类实现定时器的使用
最新推荐文章于 2023-06-30 16:38:11 发布