Skip to content

Having two bean factory methods with different return type results in NoSuchBeanDefinitionException [SPR-17437] #21970

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

Closed
spring-projects-issues opened this issue Oct 26, 2018 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

Matúš Sekáč opened SPR-17437 and commented

When I create two bean factory methods with the same name and different return type (and with qualifiers of course), the Application Context fails to start and the error message suggests that there is no bean of either type defined. This is misleading error message. It should either work (all information to distinguish beans is there), or fail with proper error message (Eg. ambiguous factory method definition).

See attached example project.


Affects: 5.0.10

Attachments:

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

snicoll commented Sep 18, 2023

Unfortunately, this does not create two beans but the context chooses the factory method that matches the state of the application context, in a similar fashion that the most suitable constructor is chosen if a target bean defines more than one.

This is confusing indeed and such arrangement is going to be deprecated.

Duplicate of #31073

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 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 18, 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

2 participants