I have followed very simple examples online to set up a cron job in Spring yet I keep getting this error in my Tomcat startup log each and every time:
2015-05
With Spring Boot 2.0.5, I keep getting:
2018-11-20 11:35:48.046 INFO 64418 --- [ restartedMain] s.a.ScheduledAnnotationBeanPostProcessor :
No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
The only way to get rid of it seems to be using SchedulingConfigurer interface in your @Configuration class like this:
@Configuration
public class SchedulerConfig implements SchedulingConfigurer {
private final int POOL_SIZE = 10;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
threadPoolTaskScheduler.setThreadNamePrefix("my-scheduled-task-pool-");
threadPoolTaskScheduler.initialize();
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
}
}
Note: This was taken from https://www.callicoder.com/spring-boot-task-scheduling-with-scheduled-annotation/