简体   繁体   English

从引导 Spring 批量应用 ItemWriter 的 @BeforeStep 方法调用 ItemProcessor 的 @BeforeStep 方法之前

[英]From boot Spring Batch application @BeforeStep method of the ItemWriter calling before of @BeforeStep method of the ItemProcessor

I'm studing SpringBatch, I have a problem during the boot Spring call ItemWriter before ItemProcessor.我正在研究SpringBatch,在启动Spring在ItemProcessor之前调用ItemWriter时出现问题。 Why?为什么?

public class PollingReader implements ItemReader<File> {
    @BeforeStep
    public void beforeStep(StepExecution stepExecution) throws NotDirectoryException {..}
    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {..}
}
    
public class PollingWriter implements ItemWriter<File> {
    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {..}
    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {..}
..
}

public class PollingProcessor implements ItemProcessor<File, File> {
    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {..}
    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {..}
}

And the method of the @AfterStep ItemProcessor is called before of the method @AfterStep ItemWriter.并且@AfterStep ItemProcessor 的方法在方法@AfterStep ItemWriter 之前被调用。

I expected this cycle call for @BeforeStep:我预计这个循环调用@BeforeStep:

  • ItemReader项目阅读器
  • ItemProcessor项目处理器
  • ItemWriter项目编写器

but I have this result:但我有这个结果:

  • ItemReader项目阅读器
  • ItemWriter项目编写器
  • ItemProcessor项目处理器

and for @AfterStep I expected:对于@AfterStep,我期望:

  • ItemWriter项目编写器
  • ItemProcessor项目处理器
  • ItemReader.项目阅读器。

but I have this result:但我有这个结果:

  • ItemProcessor项目处理器
  • ItemWriter项目编写器
  • ItemReader项目阅读器

Thanks:)谢谢:)

Your objects are polymorphic: they are both item reader/processor/writer and StepExecutionListener s (as proxies, to be more precise).您的对象是多态的:它们既是项目读取器/处理器/写入器,又StepExecutionListener (更准确地说是代理)。 When Spring Batch runs StepExecutionListeners before/after a step, it does not see them as reader/processor/writer, and the order of their execution is not necessarily the same as they are called in a chunk-oriented step (in fact, the order is undefined in that case).当 Spring Batch 在一个 step 之前/之后运行 StepExecutionListeners 时,它不会将它们视为 reader/processor/writer,并且它们的执行顺序不一定与在面向 chunk 的 step 中调用它们的顺序相同(实际上,顺序在这种情况下是未定义的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Spring Batch 的 beforeStep 中停止作业 - Stopping a Job in the beforeStep in Spring Batch 如何从 StepExecutionListener 中的 beforeStep 方法中跳过步骤执行? - How to skip a step execution from beforeStep method in StepExecutionListener? Spring Batch 不执行 StepExecutionListener beforeStep 或 afterStep 方法 - Spring Batch not executing StepExecutionListener beforeStep or afterStep methods Spring-batch @BeforeStep 不适用于 @StepScope - Spring-batch @BeforeStep does not work with @StepScope 在单元测试执行期间未调用@BeforeStep方法 - @BeforeStep method is not called during unit test execution 如何使用复合项目处理器在 spring 批处理中使用 @BeforeStep 获取 jobId? - How to get jobId with @BeforeStep in spring batch with compositeItem processor? 在@BeforeStep之前初始化测试中的Mocks - Initialize Mocks in test before @BeforeStep Spring 批处理 - 如何将多个项目的列表从输入传递到 ItemReader、ItemProcessor 和 ItemWriter - Spring Batch- how to pass list of multiple items from input to ItemReader, ItemProcessor and ItemWriter 在Spring Batch中调用ItemReader,ItemProcessor,ItemWriter的构造函数时? - When constructors for ItemReader, ItemProcessor, ItemWriter are called in Spring Batch? 在 Spring Boot 应用程序的 @Transactional 方法中调用 flush() - Calling flush() in @Transactional method in Spring Boot application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM