Description
Jeff opened BATCH-2501 and commented
When adding listeners to a step using the step builder, the step builder only broadcasts to listeners that use listener annotations, such as @OnReadError
. Listeners that implement interfaces, such as "public class ExceptionListener implements ItemWriteListener", never receive broadcasted events.
stepBuilderFactory.get("somethingFlatIdStep")
.<TheObjectType, TheObjectType> chunk(25000)
.reader(somethingFlatIdReader)
.processor(new PassThroughItemProcessor<TheObjectType>())
.writer(somethingFlatIdWriter)
.transactionAttribute(ConfigUtil.makeTransAttribute())
.listener(new ExceptionListener())
.listener(new AnnotationEventListener())
.build();
Two files attached exemplifying a listener class that doesnt work (uses spring batch listener interfaces) and a listener clas that does work (uses listener annotations).
Affects: 3.0.6
Attachments:
- AnnotationEventListener.java (1.95 kB)
- ExceptionListener.java (2.52 kB)
Activity
spring-projects-issues commentedon Apr 22, 2016
Michael Minella commented
We have methods that accept each of the listeners. I think the issue is that you've implemented multiple interfaces on the same class which is causing java to pick the
listener(Object listener)
option instead of the one for the specific interface. We can improve this, but in the short term, a work around should be to cast to any of the interfaces you are implementing:Let fluent setters of SimpleStepBuilder return proper type
fmbenhassine commentedon Jul 19, 2022
Resolved with #3989 .
[-]StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces [BATCH-2501][/-][+]StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces[/+]