Spring 批处理:单个作业的多个 JobExecutionListener 实例的执行顺序

Spring Batch : Execution order for multiple JobExecutionListener instances for a single job

给定一个 Spring Batch 作业,其中配置了 JobExecutionListener 个实例列表,每个侦听器的执行顺序是什么。示例:

<job id="myJob" xmlns="http://www.springframework.org/schema/batch">

        <batch:listeners>
            <batch:listener ref="myJobExecutionListener1" />
            <batch:listener ref="myJobExecutionListener2" />
            <batch:listener ref="myJobExecutionListener3" />
            <batch:listener ref="myJobExecutionListener4" />                
        </batch:listeners>

       <!-- job config continues -->
</job>

在上面的例子中,是否保证监听器将按照配置的顺序执行,或者监听器将以随机顺序执行。我尝试查看 Spring Batch 参考文档,但就我的研究而言,我找不到这个文档。

侦听器将按其声明顺序执行。在您的示例中,它们将按以下顺序调用:

myJobExecutionListener1.beforeJob
myJobExecutionListener2.beforeJob
myJobExecutionListener3.beforeJob
myJobExecutionListener4.beforeJob

// .. job output

myJobExecutionListener4.afterJob
myJobExecutionListener3.afterJob
myJobExecutionListener2.afterJob
myJobExecutionListener1.afterJob