我最近将我的 Spring Boot 应用程序 2.1.9 更新到 2.2.0,我遇到了一个问题。当我从执行器端点调用“configprops”时,抛出异常:范围'job'对于当前线程不是活动的
我重现了这个错误:https ://github.com/guillaumeyan/bugspringbatch (只需启动测试)。原始项目来自https://github.com/spring-guides/gs-batch-processing/tree/master/complete
我试图添加:
@Bean
public StepScope stepScope() {
final StepScope stepScope = new StepScope();
stepScope.setAutoProxy(true);
return stepScope;
}
但它不起作用(使用 spring.main.allow-bean-definition-overriding=true)
这是我对spring批处理的配置
@Bean
@JobScope
public RepositoryItemReader<DossierEntity> dossierToDiagnosticReader(PagingAndSortingRepository<DossierEntity, Long> dossierJpaRepository, @Value("#{jobParameters[origin]}") String origin) {
RepositoryItemReader<DossierEntity> diagnosticDossierReader = new RepositoryItemReader<>();
diagnosticDossierReader.setRepository(dossierJpaRepository);
diagnosticDossierReader.setMethodName("listForBatch");
// doing some stuff with origin
return diagnosticDossierReader;
}
ExceptionHandlerExceptionResolver[199] - Resolved [org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'scopedTarget.dossierToDiagnosticReader': Scope 'job' is not active for the current thread;
consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for job scope]