Skip to content

FailureAnalyzer for NoSuchBeanDefinitionException #6612

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
kelapure opened this issue Aug 10, 2016 · 7 comments
Closed

FailureAnalyzer for NoSuchBeanDefinitionException #6612

kelapure opened this issue Aug 10, 2016 · 7 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@kelapure
Copy link

kelapure commented Aug 10, 2016

One of the most common startup failures for Spring Applications is the org.springframework.beans.factory.NoSuchBeanDefinitionException.

There are multiple causes for this exception ranging from Spring Beans not annotated correctly to the incorrect spring profile being in effect.

A failure analyzer that analyzes and introspects the classpath to suggest possible candidates for injection when this exception is thrown will considerably improve the debugging and onramp of application developers with the spring frameowork.

The NoSuchBeanDefinitionFailureAnalyzer will give clues and hints on which classes could potentially be Spring beans that could be injected with some work on the developers part.

This is a Feature enhancement only applicable for SpringBoot 1.4+ projects

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 10, 2016
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 11, 2016
@techlogix
Copy link

Completely agree Rohit, we spent 2-3 hours just finding and annotating beans during a migration effort. This feature enhancement would help fortune 500 companies

@snicoll snicoll added this to the 1.4.1 milestone Aug 11, 2016
@snicoll snicoll self-assigned this Aug 11, 2016
@wilkinsona
Copy link
Member

I wonder if we could use the auto-configuration report to find beans that would have matched and to describe why they weren't available.

@kelapure
Copy link
Author

Absolutely. Most of the time the beans exist but are not candidates for injection due to various filter. We basically need to look at all the candidate beans for an injection that were filtered and report on those.

@snicoll
Copy link
Member

snicoll commented Aug 23, 2016

Reusing the auto-configuration report is brilliant but we'll have to update it a bit to make that work (or live with the limitation). The biggest problem I can see right now is that if we have several methods with the same name and different arguments only one entry is recorded for them all. The culprit is in SpringBootCondition that generates a String with the form classname#methodname with no discriminant whatsoever for the arguments.

Granted, several @Bean method with the bean name is weird (for one, you'd have to give a different name via the annotation or associate a custom BeanNameGenerator to the context. Regardless, it would be nice if the contract would be a bit stronger so that we now exactly what ends up in the report rather than parsing a String and guessing.

I am working on a prototype ignoring those limitations for now, we can certainly revisit that once we have something in place.

@snicoll
Copy link
Member

snicoll commented Aug 25, 2016

I've requested an improvement in Spring Framework to be able to handle cases where a qualifier was required.

snicoll added a commit to snicoll/spring-boot that referenced this issue Aug 26, 2016
This commit adds a `FailureAnalyzer` that handles the case where the
context does not start because no candidate bean was found for an
`InjectionPoint`.

The implementation inspects the auto-configuration report for beans
that are candidate and output the condition(s) that lead to such beans
to be discarded on startup. If a whole auto-configuration class is
disabled (or excluded), its beans are inspected and candidates are
extracted in a similar way.

This works for both injection by type and by name.

See spring-projectsgh-6612
@btiernay
Copy link

I actually created something like this in my project as well. I think the FailureAnalyzer feature is extremely useful. Hopefully one day this will be a thing of the past for Spring Boot applications:

https://www.reddit.com/r/programming/comments/3izji8/longest_stacktrace_i_have_ever_seen_in_java/

philwebb pushed a commit to philwebb/spring-boot that referenced this issue Aug 30, 2016
This commit adds a `FailureAnalyzer` that handles the case where the
context does not start because no candidate bean was found for an
`InjectionPoint`.

The implementation inspects the auto-configuration report for beans
that are candidate and output the condition(s) that lead to such beans
to be discarded on startup. If a whole auto-configuration class is
disabled (or excluded), its beans are inspected and candidates are
extracted in a similar way.

This works for both injection by type and by name.

See spring-projectsgh-6612
snicoll added a commit to snicoll/spring-boot that referenced this issue Sep 2, 2016
This commit adds a `FailureAnalyzer` that handles the case where the
context does not start because no candidate bean was found for an
`InjectionPoint`.

The implementation inspects the auto-configuration report for beans
that are candidate and output the condition(s) that lead to such beans
to be discarded on startup. If a whole auto-configuration class is
disabled (or excluded), its beans are inspected and candidates are
extracted in a similar way.

This works for both injection by type and by name.

See spring-projectsgh-6612
@philwebb
Copy link
Member

philwebb commented Sep 7, 2016

@snicoll I tweaked some things so you might want to review commit b450fec when you're back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants