[英]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:
but I have this result:但我有这个结果:
and for @AfterStep I expected:对于@AfterStep,我期望:
but I have this result:但我有这个结果:
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.