没有符合条件的 ScheduledExecutorService 类型的 bean |任务调度器

No qualifying bean of type ScheduledExecutorService | TaskScheduler

这是调度配置

@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);
    }
}

库存处理器如下

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

执行过程中,在调试日志中出现以下错误

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

我是不是漏了什么

我已经使用了这个表格我的 xml Spring 配置:

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

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

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

我的组件处理器是:

@Component
public class QueueConsumer {

    @Autowired
    ProcessQueue queue;

    @Autowired
    TaskProcessor processor;

    @Autowired
    TaskResultRepository resultRepository;

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

您需要相当于 <task:scheduler id="scheduler" pool-size="10"/>

的注释

如果您正在使用 Java 配置,您需要为您希望使用的调度程序类型定义一个 @Bean。 Spring 没有为此的默认 bean。例如

@Bean
public TaskScheduler taskScheduler() {
    return new ConcurrentTaskScheduler(); //single threaded by default
}