No qualifying bean of type ScheduledExecutorService | TaskScheduler
Asked Answered
G

2

10

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

Govea answered 14/3, 2017 at 14:49 Comment(0)
N
21

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
}
Nicotinism answered 14/3, 2017 at 14:58 Comment(4)
you mean additionally along with RWInventoryProcessor @Bean method ? or I need to extend | implement RWInventoryProcessor my with ConcurrentTaskSchedulerGovea
In any class that is annotated with @Configuration and picked up with Spring, so yes could be alongside RWInventoryProcessorNicotinism
Perfect, Here some detailed explanation docs.spring.io/spring/docs/current/javadoc-api/org/….Govea
One more question related to this #42791523 could you checkGovea
A
0

I have used this form my xml Spring Configuration:

<task:annotation-driven  executor="executor" />

<task:scheduler id="scheduler" pool-size="10"/>

<task:executor id="executor" pool-size="7"/>

My Component processor is:

@Component
public class QueueConsumer {

    @Autowired
    ProcessQueue queue;

    @Autowired
    TaskProcessor processor;

    @Autowired
    TaskResultRepository resultRepository;

    @Scheduled(fixedDelay = 15000)
    public void runJob() {
        ProcessTask task = queue.poll();
        ...
    }
}

You need the annotation equivalent to <task:scheduler id="scheduler" pool-size="10"/>

Actinochemistry answered 14/3, 2017 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.