Skip to content

Introduce addListener method in StepBuilder and JobBuilder for better clarity#5323

Open
nikitanagar08 wants to merge 1 commit intospring-projects:mainfrom
nikitanagar08:feature-5321-add-listener-methods
Open

Introduce addListener method in StepBuilder and JobBuilder for better clarity#5323
nikitanagar08 wants to merge 1 commit intospring-projects:mainfrom
nikitanagar08:feature-5321-add-listener-methods

Conversation

@nikitanagar08
Copy link

Fixes #5321

Motivation

The current .listener() method in StepBuilder and JobBuilder can be ambiguous. A method named after a property (without a prefix) often implies setting a single value, potentially overwriting previous ones. However, in Spring Batch, calling .listener() multiple times actually appends the listeners to an internal list rather than replacing them.

Proposed Change

Added addListener() methods as aliases that delegate to the existing listener() methods. The new method names make the additive behavior explicit and improve API consistency.

Benefits

  • Improved Readability: addListener makes it clear that the listener is being added to a collection
  • API Consistency: Aligns with modern Java libraries where add* is used for collection-based properties
  • Self-Documenting Code: Reduces the need for developers to check the internal implementation or Javadoc

Changes

  • StepBuilderHelper.addListener(StepExecutionListener) - delegates to listener()
  • StepBuilderHelper.addListener(Object) - delegates to listener() for annotation-based config
  • JobBuilderHelper.addListener(JobExecutionListener) - delegates to listener()
  • JobBuilderHelper.addListener(Object) - delegates to listener() for annotation-based config

Backward Compatibility

The existing .listener() methods remain for full backward compatibility.

… clarity

Fixes spring-projects#5321

Add addListener() methods as aliases that delegate to the existing listener()
methods. The new method names make the additive behavior of adding listeners
explicit and improve API consistency.

Changes:
- StepBuilderHelper.addListener(StepExecutionListener) - delegates to listener()
- StepBuilderHelper.addListener(Object) - delegates to listener() for annotation-based config
- JobBuilderHelper.addListener(JobExecutionListener) - delegates to listener()
- JobBuilderHelper.addListener(Object) - delegates to listener() for annotation-based config

The existing listener() methods remain for backward compatibility.

Signed-off-by: Nikita Nagar <permanayan84@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce addListener method in StepBuilder and JobBuilder for better clarity

1 participant