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

Beans defined by XML are skipped in @Configuration override [SPR-15805] #20360

Closed
spring-projects-issues opened this issue Jul 21, 2017 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 21, 2017

David Lopez opened SPR-15805 and commented

When you define a bean in a XML, you cannot redefine it in a @Component or @TestComponent class using a @Bean declaration). It can, however, be redefined using another XML.

I have defined this as a Improvement since I do not think it explicitly violates anything .. simply it is a grey zone in the DI part fo Spring, but anyway, I consider this behaviour inconsistent and weird.

This issue is similar to #14201, but to the case when


Affects: 4.3.9, 5.0 RC2

Attachments:

Issue Links:

1 votes, 1 watchers

@spring-projects-issues
Copy link
Collaborator Author

David Lopez commented

Added an example: it is a dummy project that defines two possible implementations of a simple interface.

There is three ways to define a bean named "stupidObject": by annotation in (the class A), in a @Configuration class (which created an A object) and importing an XML (which defined it as a instance of A too).

There is an unit test that tries to redefine the bean "stupidObject" using a @TestConfiguration inner class by the second implementation B. It successes in the case of defining the bean using annotations or Java Config. But when the instance is defined thru XML, it cannot be redefined.

The test used Spring Boot, but it is not really necessary to check this scenario.

@spring-projects-issues spring-projects-issues added status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: enhancement A general enhancement label Jan 11, 2019
@snicoll snicoll self-assigned this Sep 20, 2023
@snicoll
Copy link
Member

snicoll commented Sep 21, 2023

Thanks for the sample, I did upgrade it to a recent version and can reproduce the behavior. XML bean definitions can't be overridden by java config bean in the sense that these are "top-level" and @Bean methods aren't (only the @Configuration class is).

In general, we feel that bean overriding shouldn't be used at all. This triggers the discussion of deprecating the feature altogether, see #31288

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 21, 2023
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) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants