In this article, we are discussing the Spring org.springframework.beans. factory.NoSuchBeanDefinitionException this is a common exception thrown by the BeanFactory when trying to resolve a bean that isn't defined in the current Spring Context.
We'll illustrate the possible causes for this problem and the available solutions.
Cause: No qualifying bean of type [?] found for dependency
The most common cause of this exception is simply trying to inject a bean that isn't defined. For example BeanQ is wiring in a collaborator BeanP:
Have a look at this Code snippet
Now, if any dependency BeanP is not defined in the Spring Context, the container process will fail with the no such bean definition exception:
We can see the reason of this exception, which is clearly indicated by Spring container: "expected at least 1 bean which qualifies as autowire candidate for this dependency"
One reason BeanQ may not exist in the spring container if beans are picked up automatically by classpath scanning, and if BeanQ is correctly annotated as a bean (@Component, @Repository, @Service, @Controller, etc) then other issue may be that BeanQ is defined in a package that is not scanned by Spring:
There might be the chances that classpath scanning may be configured as follows:
If beans are not automatically scanned, then BeanQ is simply not defined in the current Spring Container.
Just change the Package scanning to Root package so that all the beans are scanned by Spring.
Looking for any Software or Tutorial?
Don't Worry, we will find it for you