Skip to content

StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces #1098

Closed
@spring-projects-issues

Description

@spring-projects-issues
Collaborator

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:

Activity

spring-projects-issues

spring-projects-issues commented on Apr 22, 2016

@spring-projects-issues
CollaboratorAuthor

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:

stepBuilderFactory.get("somethingFlatIdStep")
    .<TheObjectType, TheObjectType> chunk(25000)
    .reader(somethingFlatIdReader)
    .processor(new PassThroughItemProcessor<TheObjectType>())
    .writer(somethingFlatIdWriter)
    .transactionAttribute(ConfigUtil.makeTransAttribute())
    .listener((ItemReadListener) new ExceptionListener())
    .listener(new AnnotationEventListener())
    .build();
added this to the 5.0.0-M4 milestone on Jul 19, 2022
fmbenhassine

fmbenhassine commented on Jul 19, 2022

@fmbenhassine
Contributor

Resolved with #3989 .

changed the title [-]StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces [BATCH-2501][/-] [+]StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces[/+] on Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @fmbenhassine@spring-projects-issues

        Issue actions

          StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces · Issue #1098 · spring-projects/spring-batch