Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StepBuilderFactory Only Supports Listener Annotations, Not Listener Interfaces #1098

Closed
spring-projects-issues opened this issue Apr 22, 2016 · 2 comments

Comments

@spring-projects-issues
Copy link
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:

@spring-projects-issues
Copy link
Collaborator Author

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();

fmbenhassine pushed a commit that referenced this issue Jul 19, 2022
Let fluent setters of `SimpleStepBuilder` return `this` with type `SimpleStepBuilder`.
This makes the required order of some fluent setters a bit more lenient and prevents
that `AbstractTaskletStepBuilder::listener` for parameters of type `Object` is invoked
although an overloaded method specific for `SimpleStepBuilder` is intended.

Fixes #773 and #1098.
@fmbenhassine fmbenhassine removed the status: waiting-for-triage Issues that we did not analyse yet label Jul 19, 2022
@fmbenhassine fmbenhassine added this to the 5.0.0-M4 milestone Jul 19, 2022
@fmbenhassine
Copy link
Contributor

Resolved with #3989 .

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

No branches or pull requests

2 participants