对于当前线程“没有可用于步骤范围的上下文持有者”,范围“步骤”无效

时间:2018-03-30 13:28:07

标签: java spring spring-batch

您好我们正在春季启动项目中集成spring批处理,但我面临此例外Scope 'step' 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 step scope

这里是我的步骤范围bean配置类:

@Bean 
@StepScope
public StaxEventItemReader<Document> xmlFileItemReader(@Value("#{jobParameters[fullPathFileName]}") String pathToFile) {
    StaxEventItemReader<Document> xmlFileReader = new StaxEventItemReader<>();
    xmlFileReader.setResource(new FileSystemResource(pathToFile));
    xmlFileReader.setFragmentRootElementName("Document");

    Jaxb2Marshaller pimMarshaller = new Jaxb2Marshaller();
    pimMarshaller.setClassesToBeBound(Document.class);

    xmlFileReader.setUnmarshaller(pimMarshaller);
    return xmlFileReader;
}

我的主要runnable类使用@EnableBatchProcessing

进行注释

1 个答案:

答案 0 :(得分:-1)

使用步进镜如下 XMl配置: