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

Configuration class parsing registers bean in parent class if overridden @Bean method defines an alternative name #28286

Closed
mpiela opened this issue Apr 5, 2022 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@mpiela
Copy link

mpiela commented Apr 5, 2022

We are experiencing a difference in behaviour when setting up a spring context in junit tests.
Here is a simple project that shows the difference: https://github.com/mpiela/spring-ctx-bug.
Usage:

mvn test

There are two tests in there:

The issue seems to be with an overriden @Bean method in a @Configuration class and omitting the bean name in the subclass.

Both of these tests pass on Spring 5.2.8. When we switched to Spring 5.2.9 the one with the xml configuration file starts failing.

I am not really sure if this is a bug that's been fixed in 5.2.8 and 5.2.9 is the expected behaviour or if it is the other way around.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 5, 2022
@sbrannen
Copy link
Member

sbrannen commented Apr 5, 2022

This may be related to the changes made in conjunction with the following issue:

In particular, see #25263 (comment).

@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Apr 5, 2022
@snicoll
Copy link
Member

snicoll commented Nov 24, 2023

Thanks for the sample.

SpringJavaConfigTest should never have worked. That base class who shadows the bean in the concrete class should not be created in the first place. Actually, we think that there's a case for throwing an exception for such an unusual use case.

From that perspective, the XML based test failing is the expected behavior. We'll tidy things up in 6.2.x to make things consistent.

@snicoll snicoll changed the title Difference in context initialization between 5.2.8 and 5.2.9 Configuration class parsing registers bean in parent class if its @Bean declaration defines an alernative name Nov 24, 2023
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 24, 2023
@snicoll snicoll added this to the 6.2.x milestone Nov 24, 2023
@jhoeller jhoeller changed the title Configuration class parsing registers bean in parent class if its @Bean declaration defines an alernative name Configuration class parsing registers bean in parent class if overridden @Bean method defines an alternative name Nov 24, 2023
@snicoll
Copy link
Member

snicoll commented Dec 12, 2023

When processing this, there is a sample demo for a similar, yet different use case that should be validated, see #28137.

@jhoeller jhoeller modified the milestones: 6.2.x, 6.2.0-M1 Jan 12, 2024
@bclozel bclozel changed the title Configuration class parsing registers bean in parent class if overridden @Bean method defines an alternative name Configuration class parsing registers bean in parent class if overridden @Bean method defines an alternative name Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants