繁体   English   中英

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

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

我正在研究SpringBatch,在启动Spring在ItemProcessor之前调用ItemWriter时出现问题。 为什么?

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) {..}
}

并且@AfterStep ItemProcessor 的方法在方法@AfterStep ItemWriter 之前被调用。

我预计这个循环调用@BeforeStep:

  • 项目阅读器
  • 项目处理器
  • 项目编写器

但我有这个结果:

  • 项目阅读器
  • 项目编写器
  • 项目处理器

对于@AfterStep,我期望:

  • 项目编写器
  • 项目处理器
  • 项目阅读器。

但我有这个结果:

  • 项目处理器
  • 项目编写器
  • 项目阅读器

谢谢:)

您的对象是多态的:它们既是项目读取器/处理器/写入器,又StepExecutionListener (更准确地说是代理)。 当 Spring Batch 在一个 step 之前/之后运行 StepExecutionListeners 时,它不会将它们视为 reader/processor/writer,并且它们的执行顺序不一定与在面向 chunk 的 step 中调用它们的顺序相同(实际上,顺序在这种情况下是未定义的)。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM