vel*_*s4j 7 java spring spring-scheduled
这是调度配置
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
库存处理器如下
public class RWInventoryProcessor {
...
@Scheduled(fixedRate = 5000,initialDelay = 3000)
@Transactional
public void runProcess() {
...
}
}
Run Code Online (Sandbox Code Playgroud)
在执行期间,在调试日志中获取以下错误
DEBUG org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor - 找不到默认的TaskScheduler bean org.springframework.beans.factory.NoSuchBeanDefinitionException:没有'org.springframework.scheduling.TaskScheduler'类型的限定bean可用
...
DEBUG org.springframework. scheduling.annotation.ScheduledAnnotationBeanPostProcessor - 找不到默认的ScheduledExecutorService bean org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'java.util.concurrent.ScheduledExecutorService'的限定bean
我错过了什么
Ada*_*dam 17
如果您正在使用Java配置,则需要针对要使用的调度程序类型的@Bean定义.Spring没有这个默认bean.例如
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler(); //single threaded by default
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18688 次 |
| 最近记录: |