【问题标题】:From boot Spring Batch application @BeforeStep method of the ItemWriter calling before of @BeforeStep method of the ItemProcessor从启动 Spring Batch 应用程序的 ItemWriter 的 @BeforeStep 方法调用 ItemProcessor 的 @BeforeStep 方法之前
【发布时间】:2021-06-06 19:03:04
【问题描述】:

我正在研究 SpringBatch,在 ItemProcessor 之前启动 Spring 调用 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 会出现这个循环调用:

  • ItemReader
  • 项目处理器
  • ItemWriter

但我有这个结果:

  • ItemReader
  • ItemWriter
  • 项目处理器

对于@AfterStep 我期望:

  • ItemWriter
  • 项目处理器
  • ItemReader.

但我有这个结果:

  • 项目处理器
  • ItemWriter
  • ItemReader

谢谢:)

【问题讨论】:

    标签: java spring-boot spring-batch


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多