Video in progress

Strong Junior 🌱 Spring

When you see "No qualifying bean of type ... available", what do you check?

Spring couldn't find a bean of that type. Usually the annotation is missing, the class isn't covered by component scan, a conditional bean (@Profile, @ConditionalOn...) wasn't created, or the type is wrong.

📖 Answer

I usually go through it in this order:

  1. Is there an annotation? Without @Service/@Component or a @Bean method, Spring doesn't know about the class.
  2. Package. If the @SpringBootApplication class is in uz.shop.app and the service is in uz.shop.billing, it won't be scanned. Move the main class to a higher-level package.
  3. Conditions. The bean has @Profile("prod") and you're running in dev. Or a @ConditionalOnProperty isn't satisfied.
  4. Type. You're asking for the implementation class, but the bean is a JDK proxy — it's only visible through the interface.
  5. Module. In a multi-module project the required module isn't added as a dependency.

Read the "Consider defining a bean..." part at the bottom of the error message. Also, if you start with --debug, you get the Conditions Evaluation Report — it tells you which auto-config didn't kick in and why.