如果类被 @Lazy 修饰导致 Spring Boot 在启动的时候没有实例化,那定时任务就不会开始执行。 @Lazy@ComponentpublicclassScheduleTask{privatestaticfinalLoggerLOGGER=LoggerFactory.getLogger(ScheduleTask.class);// 此时定时任务不会被执行@Scheduled(cron="* * * * * ?")publicvoidprintLog(){LOGGER.warn("执行...
package com.badao.demo.task; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; @Configuration @EnableS...