Hello Spring Batch team,
First of all, thank you for all your hard work maintaining and improving Spring Batch6. I have encountered a small behavior in ChunkOrientedStepBuilder related to listener registration that I believe could be improved for consistency and usability.
Expected Behavior
ChunkOrientedStepBuilder should allow StepExecutionListener instances to be registered in the stepListeners collection so that they participate in automatic type-based listener registration during build().
Currently, build() iterates over stepListeners and registers each listener for all interfaces it implements:
stepListeners.forEach(stepListener -> {
if (stepListener instanceof ItemReadListener listener) {
chunkOrientedStep.registerItemReadListener(listener);
}
if (stepListener instanceof ItemProcessListener listener) {
chunkOrientedStep.registerItemProcessListener(listener);
}
if (stepListener instanceof ItemWriteListener listener) {
chunkOrientedStep.registerItemWriteListener(listener);
}
if (stepListener instanceof ChunkListener listener) {
chunkOrientedStep.registerChunkListener(listener);
}
if (stepListener instanceof StepExecutionListener listener) {
chunkOrientedStep.registerStepExecutionListener(listener);
}
});
With this logic, a single StepListener implementation that implements multiple listener interfaces (e.g., StepExecutionListener and ItemReadListener) will be registered for all applicable listener types.
To make this work, StepExecutionListener instances should also be added to stepListeners when registered via ChunkOrientedStepBuilder.listener(StepExecutionListener):
@Override
public ChunkOrientedStepBuilder<I, O> listener(StepExecutionListener listener) {
this.stepListeners.add(listener);
return self();
}
Current Behavior
Currently, registering a StepExecutionListener via StepBuilderHelper.listener(StepExecutionListener) adds it only to properties.stepExecutionListeners. These listeners are applied to the step only through super.enhance() in build(), and do not enter the stepListeners collection.
As a result, StepExecutionListener implementations that also implement other listener interfaces (ItemReadListener, ItemProcessListener, ItemWriteListener, etc.) are not automatically registered for those additional interfaces.
Context
This affects any case where a StepExecutionListener is also intended to act as an ItemReadListener, ItemProcessListener, or ItemWriteListener. Without overriding listener(StepExecutionListener) in ChunkOrientedStepBuilder to add the listener to stepListeners, the automatic registration mechanism cannot detect and register these additional interfaces.
Overriding listener(StepExecutionListener) in ChunkOrientedStepBuilder would make listener registration consistent with other listener types and fully leverage the multi-interface automatic registration logic in build().
Thank you very much for considering this improvement. I look forward to your thoughts and guidance.
Hello Spring Batch team,
First of all, thank you for all your hard work maintaining and improving Spring Batch6. I have encountered a small behavior in ChunkOrientedStepBuilder related to listener registration that I believe could be improved for consistency and usability.
Expected Behavior
ChunkOrientedStepBuilder should allow StepExecutionListener instances to be registered in the stepListeners collection so that they participate in automatic type-based listener registration during build().
Currently, build() iterates over stepListeners and registers each listener for all interfaces it implements:
With this logic, a single StepListener implementation that implements multiple listener interfaces (e.g., StepExecutionListener and ItemReadListener) will be registered for all applicable listener types.
To make this work, StepExecutionListener instances should also be added to stepListeners when registered via ChunkOrientedStepBuilder.listener(StepExecutionListener):
Current Behavior
Currently, registering a StepExecutionListener via StepBuilderHelper.listener(StepExecutionListener) adds it only to properties.stepExecutionListeners. These listeners are applied to the step only through super.enhance() in build(), and do not enter the stepListeners collection.
As a result, StepExecutionListener implementations that also implement other listener interfaces (ItemReadListener, ItemProcessListener, ItemWriteListener, etc.) are not automatically registered for those additional interfaces.
Context
This affects any case where a StepExecutionListener is also intended to act as an ItemReadListener, ItemProcessListener, or ItemWriteListener. Without overriding
listener(StepExecutionListener)in ChunkOrientedStepBuilder to add the listener to stepListeners, the automatic registration mechanism cannot detect and register these additional interfaces.Overriding
listener(StepExecutionListener)in ChunkOrientedStepBuilder would make listener registration consistent with other listener types and fully leverage the multi-interface automatic registration logic in build().Thank you very much for considering this improvement. I look forward to your thoughts and guidance.