W3docs

@Autowired - No qualifying bean of type found for dependency

No qualifying bean of type found for dependency is an error message that can occur when you are using the @Autowired annotation in Spring to inject a bean dependency.

No qualifying bean of type found for dependency is an error message that can occur when you are using the @Autowired annotation in Spring to inject a bean dependency. It usually indicates that the Spring framework is unable to find a bean of the required type in the application context.

This error can occur for several reasons, such as:

  • The required bean is not defined in the application context.
  • The required bean is defined, but it is not of the expected type.
  • The required bean is missing a proper bean definition (e.g., missing @Component, @Service, or @Bean) or is in a package not covered by @ComponentScan.

To troubleshoot this error, you can try the following:

  • Make sure that the required bean is defined in the application context. For example:
    // ❌ Missing annotation - not registered as a bean
    public class MyService { ... }
    
    // ✅ Properly annotated - registered as a bean
    @Service
    public class MyService { ... }
  • Check the type of the required bean to make sure it matches the expected type. Use @Qualifier if multiple beans of the same type exist.
  • Verify your component scanning configuration. If the bean is in a different package than your main application class, add @ComponentScan(basePackages = "com.example.yourpackage") to your configuration.

It might also be helpful to enable debug logging for the Spring framework, as this can provide more information about the cause of the error. Add the following to your application.properties:

logging.level.org.springframework=DEBUG