Skip to content

Enable proper override of binder beans with user-defined configurations in a multi-binder scenario #3123

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ferblaca
Copy link
Contributor

closes #3114

…user-defined beans over binder's conditional beans in a multi-binder scenario

This change modifies the loading order in DefaultBinderFactory.initializeBinderContextSimple
to ensure that user configuration classes specified via spring.main.sources are loaded before
binder configuration classes. This allows @ConditionalOnMissingBean annotations in the binder
configurations to properly detect user-provided beans.

Previously, when using KafkaBinderConfiguration with @ConditionalOnMissingBean(KafkaBinderMetrics.class),
even if the user had configured a custom KafkaBinderMetrics bean via spring.main.sources,
the condition would not work correctly because binder classes were loaded first.

Fixes spring-cloudgh-3114

Signed-off-by: ferblaca <fernandobc@ext.inditex.com>
@sobychacko
Copy link
Contributor

@ferblaca I thought you would add a ConditionalOnProperty on KafkaBinderMetrics, no? What made you change DefaultBinderFactory instead? Thanks!

@ferblaca
Copy link
Contributor Author

ferblaca commented Jun 18, 2025

Hi @sobychacko!!

After reviewing the issue, I noticed that it seemed to be a more general BUG in DefaultBinderFactory, since the @ConditionalOnMissingBean conditions in the binder configurations would not work in multi-binder scenarios, not just for the Kafka binder, but for all of them.

And to avoid mixing things up, I preferred to create this PR to solve this more general problem first, so the [kafka][metrics] labels in the title do not make sense for this PR and issue. I will update them, also the issue description to adapt it to PR.

@ferblaca ferblaca changed the title [kafka][metrics] Enable proper override of binder beans with user-defined configurations in a multi-binder scenario Enable proper override of binder beans with user-defined configurations in a multi-binder scenario Jun 18, 2025
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.

Enable proper override of binder beans with user-defined configurations in a multi-binder scenario
2 participants