Spring-Scheduling
Spring 定时任务 Author: HuiFer 源码阅读仓库: SourceHot-spring EnableScheduling 首先关注的类为启动定时任务的注解@EnableScheduling 1 2 3 4 5 6 7 @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Import(SchedulingConfiguration.class) @Documented public @interface EnableScheduling { } SchedulingConfiguration 注册定时任务相关信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 @Configuration @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public class SchedulingConfiguration { /** * 开启定时任务 * @return */ @Bean(name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME) @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public ScheduledAnnotationBeanPostProcessor scheduledAnnotationProcessor() { // 注册 ScheduledAnnotationBeanPostProcessor return new ScheduledAnnotationBeanPostProcessor(); } } ScheduledAnnotationBeanPostProcessor 关注 application 事件,以及 spring 生命周期……