Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No qualifying bean of type ScheduledExecutorService | TaskScheduler

Here is the Scheduling Configuration

@Configuration
@EnableScheduling
public class RWInventorySchedule {

protected org.slf4j.Logger log = LoggerFactory.getLogger(RWInventorySchedule.class);

@PersistenceContext
private EntityManager entityManager;


   @Bean
   public RWInventoryProcessor constructInventoryProcessor() {
       log.debug("RWInventorySchedule constructs InventoryProcessor, entityManager : {} " , entityManager);
       return new RWInventoryProcessor(entityManager);
    }
}

Inventory Processor is the following

public class RWInventoryProcessor  {
 ...
 @Scheduled(fixedRate = 5000,initialDelay = 3000)
 @Transactional
 public void runProcess() {
   ...
 }
}

During execution, getting the following errors in debug log

DEBUG org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor - Could not find default TaskScheduler bean org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.scheduling.TaskScheduler' available

...
DEBUG org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor - Could not find default ScheduledExecutorService bean org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.concurrent.ScheduledExecutorService' available

Am I missing anything

like image 266
vels4j Avatar asked Mar 14 '17 14:03

vels4j


1 Answers

If you're using Java configuration you need an @Bean definition for the type of scheduler you wish to use. Spring does not have a default bean for this. For example

@Bean
public TaskScheduler taskScheduler() {
    return new ConcurrentTaskScheduler(); //single threaded by default
}
like image 182
Adam Avatar answered Sep 28 '22 10:09

Adam