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

Enhancement - Bean name duplication #23653

Closed
artemptushkin opened this issue Sep 18, 2019 · 4 comments
Closed

Enhancement - Bean name duplication #23653

artemptushkin opened this issue Sep 18, 2019 · 4 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@artemptushkin
Copy link

artemptushkin commented Sep 18, 2019

#enhancement

A case:

@Bean
public SomeOne aBean() {
     return new SomeOne();
}

@Bean
public AnotherOne aBean() {
     return new AnotherOne();
}

In this case, I'll get NoSuchBeanDefinitionException on autowiring AnotherOne

It is confusing because of the root of exception in bean names duplication on anotherOne overrides previous bean definition

I think It will be convenient to get a specific exception or warning.
If there is already some mechanism please let me know and I'll request close the issue

Of course, it is about naming, and it should not be named as in the example above. But my point in case of carelessness and framework feedback

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 18, 2019
@abhishek-abhi
Copy link

I want to contribute to resolve the issue. Can you assign this to me ?

@artemptushkin
Copy link
Author

@abhishek-abhi no, have no permissions. TY! Open a PR, I'll review

@snicoll
Copy link
Member

snicoll commented Sep 24, 2019

@abhishek-abhi thank you for offering to help. There is no need to ask for assignment, a note that states you'll provide a PR short term is more than enough. This issue hasn't been triaged by the team yet: to avoid you spending time for something that would'd be declined, please wait for an issue to be triaged and assigned to a milestone.

@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 10, 2021
@snicoll
Copy link
Member

snicoll commented Sep 26, 2023

In this case, I'll get NoSuchBeanDefinitionException on autowiring AnotherOne

That's because you've overwritten one bean with another since they have the same ID (collected from the method name). This is indeed a surprising behavior and we've decided to deprecate it (it is already disabled by default in Spring Boot for quite a while).

See #31288

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 26, 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: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

5 participants