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-25 00:32:58 DEBUG ScheduledAnnotationBeanPostProcessor:191 -
Could not find default TaskScheduler bean org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
2015-05-25 00:32:58 DEBUG ScheduledAnnotationBeanPostProcessor:202 - Could not
find default ScheduledExecutorService bean
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying
bean of type [org.springframework.scheduling.TaskScheduler] is defined
And the 2 java classes used to implement the cron:
The @Configuration class:
@Configuration @EnableScheduling public class ClearTokenStoreCronEnable { final static Logger log = LoggerFactory.getLogger(ClearTokenStoreCronEnable.class); private @Autowired TokenStoreRepository tokenStoreRepository; }
and Cron job class:
@Service public class ClearTokenStoreWorkerService { final static Logger log = LoggerFactory.getLogger(ClearTokenStoreWorkerService.class); private @Autowired TokenStoreRepository tokenStoreRepository; //@Scheduled(fixedDelay=5000) //run daily at midnight @Scheduled(cron = "0 0 * * * *") public void tokenStoreTable() { log.debug("tokenstore table truncated - start"); tokenStoreRepository.deleteAll(); log.debug("tokenstore table truncated - end"); } }
As a side note, the cron job runs at midnight but it also seems to run randomly at other times. Not sure if this is a bug or my cron expression is wrong:
@Scheduled(cron = "0 0 * * * *")
My main concern at this time is why am I getting ScheduledAnnotationBeanPostProcessor
errors? It's looking for a TaskScheduler and ScheduledExectorService. I just need to fire this once a day. I am not doing any concurrent processing or where I need multiple threads. Ultimately are these errors harmful OR do I need to fix them?