问题
基于Spring-boot实现一个定时任务,发现任务不执行。
代码实现
@Component
public class JobTest {
private static final Logger logger = LoggerFactory.getLogger(JobTest.class);
@Scheduled(cron = "* * * * * ?")
public void monitorTask() {
logger.info("job is running ok");
}
}
解决
排查了好久,最后发现启动类少了一个@EnableScheduling注解,该注解的意思是开启定时任务,添加注解后,任务日志开始输出。