I searched existing issues and found related listener-registration issues such as #5092, #5094, and #5347, but I could not find a duplicate for this specific case.
Bug description
ChunkOrientedStepBuilder#listener(Object) ignores annotation-based listeners that only declare @BeforeStep or @AfterStep methods.
The same object is registered if it also has another chunk/item listener annotation, such as @BeforeRead.
Environment
Spring Batch: 6.0.4
Java: 21
Steps to reproduce
Register a POJO with only a step-level listener annotation on a chunk-oriented step:
AtomicInteger called = new AtomicInteger();
Object listener = new Object() {
@BeforeStep
public void beforeStep(StepExecution stepExecution) {
called.incrementAndGet();
}
};
ChunkOrientedStep<String, String> step = new StepBuilder("step", new ResourcelessJobRepository())
.<String, String>chunk(1)
.reader(new ListItemReader<>(List.of("item")))
.writer(chunk -> {
})
.listener(listener)
.build();
step.execute(new StepExecution("step", new JobExecution(1L, new JobInstance(1L, "job"), new JobParameters())));
assertThat(called).hasValue(1); // currently 0
Expected behavior
@BeforeStep and @AfterStep methods should be detected by ChunkOrientedStepBuilder#listener(Object).
Minimal Complete Reproducible example
The snippet above reproduces the issue.
I searched existing issues and found related listener-registration issues such as #5092, #5094, and #5347, but I could not find a duplicate for this specific case.
Bug description
ChunkOrientedStepBuilder#listener(Object)ignores annotation-based listeners that only declare@BeforeStepor@AfterStepmethods.The same object is registered if it also has another chunk/item listener annotation, such as
@BeforeRead.Environment
Spring Batch: 6.0.4
Java: 21
Steps to reproduce
Register a POJO with only a step-level listener annotation on a chunk-oriented step:
Expected behavior
@BeforeStepand@AfterStepmethods should be detected byChunkOrientedStepBuilder#listener(Object).Minimal Complete Reproducible example
The snippet above reproduces the issue.