gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:46:46 25 4
gpt4 key购买 nike

这是调度配置

@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

我是不是漏了什么

最佳答案

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

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

关于java - 没有符合条件的 ScheduledExecutorService 类型的 bean |任务调度器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42789209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com