Spring Autowire NoSuchBeanDefinitionException

Here is an example of the NoSuchBeanDefinitionException you may see thrown by the Spring context:

NoSuchBeanDefinitionException

1

2

3

4

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [guru.springframework.controllers.HelloController] is defined

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:372)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1060)

By default, Spring will Autowire beans by type. You can see in the error message the type of bean Spring is expecting to find. The problem is that the Spring Context is not finding a Java class of this type configured for use. There are a couple small gotch ya’s when using the Spring Boot application and in how Spring Boot scans for eligible Spring Beans.

Free Introduction to Spring Tutorial

Are you new to the Spring Framework? Checkout my Free Introduction to Spring Online Tutorial.