没有限定型豆类型exchecutorService | Taskscheduler

问题描述 投票:0回答:2

在这里是调度配置

@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处理器是以下

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

执行,在调试日志中获取以下错误

depebug org.springframework.scheduling.annotation.scheduledannotationbeanbeanpostProcessor - 找不到默认任务Cheduler bean org.springframework.beans.factory.nosuchbeandefinitionException:否 'org.springframework.scheduling.taskscheduler'的合格豆 可用的

...
debug org.springframework.scheduling.annotation.scheduledannotationbeanpostprocessor - 找不到默认的speculedexecutorService bean org.springframework.beans.factory.nosuchbeandefinitionException:否 合格的豆类 'Java.util.concurrent.scheduledexecutorservice'可用


我错过了任何东西

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

@Bean public TaskScheduler taskScheduler() { return new ConcurrentTaskScheduler(); //single threaded by default }
java spring spring-scheduled
2个回答
21
投票

我已经使用了此表格我的XML弹簧配置:

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

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

<task:executor id="executor" pool-size="7"/>
我的组件处理器是:

0
投票
@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"/>
的注释
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.