Spring Boot: No qualifying bean of type available
The context could not satisfy a constructor argument. Scan boundaries, missing stereotypes, ambiguous candidates and test slices are the usual reasons.

Introduction & Quick Summary
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.example.billing.InvoiceService required a bean of type
'com.example.billing.TaxCalculator' that could not be found.
Action:
Consider defining a bean of type 'com.example.billing.TaxCalculator' in your configuration.Spring resolved the dependency graph to the point of InvoiceService, found no candidate for TaxCalculator, and stopped the context refresh. The message names the injection point and the exact type, so the work is finding why that type has no bean, not why the application failed.
The five reasons, in the order Spring Boot users actually hit them:
- No stereotype annotation. The class is a POJO; without
@Component,@Service,@Repositoryor a@Beanmethod, nothing registers it. - Component scan never reached the package.
@SpringBootApplicationscans its own package and below. A class in a sibling package, or one moved during a refactor, is invisible. - An interface with no implementation registered. The interface is scanned but not instantiable, and the implementation lives in a module that is not on the classpath.
- More than one candidate, none preferred. Two implementations exist and neither is
@Primarynor selected with@Qualifier, which yields the "expected single matching bean but found 2" variant. - A condition excluded it.
@ConditionalOnProperty,@Profile, or a test slice such as@WebMvcTestdeliberately loads only part of the context.
| Message variant | Meaning | Fix |
|---|---|---|
required a bean of type ... that could not be found | Zero candidates | Annotate, scan, or define a bean |
No qualifying bean of type ... available | Zero candidates at lookup | Same |
expected single matching bean but found 2 | Ambiguous candidates | @Primary or @Qualifier |
No bean named 'x' available | Named lookup, not type | Fix @Qualifier("x") |
| Fails only in tests | Slice test context | Add @MockBean or import the config |
Core Mechanics, Signatures & Reproducible Setup
@SpringBootApplication is three annotations: @ComponentScan, @EnableAutoConfiguration and @Configuration. The scan base package is the package of the annotated class, so moving a @SpringBootApplication class into com.example.app makes everything under com.example.services unreachable unless you widen the scan.
A minimal reproduction shows the scan boundary:
com/example/app/Application.java @SpringBootApplication
com/example/app/InvoiceService.java @Service, injects TaxCalculator
com/example/billing/TaxCalculator.java @ServiceParameter 0 of constructor in com.example.app.InvoiceService required a bean of type
'com.example.app.TaxCalculator' that could not be found.Three legitimate fixes, with different costs:
// 1. Widen the scan
@SpringBootApplication(scanBasePackages = {"com.example.app", "com.example.billing"})
public class Application {}
// 2. Move the application class up
// com/example/Application.java with packages under com.example.*
// 3. Import the module's configuration explicitly
@Import(BillingConfig.class)
public class Application {}For a library module that should not expose a scan package, exporting an auto-configuration is cleaner:
@AutoConfiguration
@ConditionalOnClass(TaxCalculator.class)
public class BillingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
TaxCalculator taxCalculator() {
return new DefaultTaxCalculator();
}
}Register it in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.
Key Comparison Table
| Annotation | Registers a bean | Typical layer | Metadata |
|---|---|---|---|
@Component | Yes | Any | None |
@Service | Yes | Business logic | Specialized @Component |
@Repository | Yes | Persistence | Adds exception translation |
@Controller | Yes | Web | Handler mapping |
@Configuration + @Bean | Yes, one per method | Wiring | Full proxying by default |
@Conditional... | Only when matched | Any | Controls registration |
| Situation | Check | Fix |
|---|---|---|
| Class in another module | Is the jar a dependency? | Add it, or import its config |
| Two implementations | --debug condition report | @Primary or @Qualifier |
| Profile-specific bean | spring.profiles.active | Activate the profile |
| Test slice | @WebMvcTest, @DataJpaTest | @Import, @MockBean |
| Generic bean | Type erasure in the message | Use a specific subtype |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
Case 1: Constructor injection added to a scanned class
@Service
public class InvoiceService {
private final TaxCalculator tax;
public InvoiceService(TaxCalculator tax) { this.tax = tax; } // fails at startup
}The error is correct: nothing provides TaxCalculator. Create it as a bean rather than nulling the constructor, because a nullable dependency only moves the NullPointerException to the first request.
Case 2: Two candidates and no qualifier
@Service("stripe") class StripePayment implements Payment {}
@Service("paypal") class PaypalPayment implements Payment {}No qualifying bean of type 'Payment' available: expected single matching bean but found 2:
paypal,stripe@Service
public class Checkout {
private final Payment payment;
public Checkout(@Qualifier("stripe") Payment payment) { this.payment = payment; }
}Naming the parameters to match bean names happens to work in recent Spring versions but is fragile after obfuscation or refactoring; use @Qualifier.
Case 3: Test slices that load only part of the context
@WebMvcTest(InvoiceController.class)
class InvoiceControllerTest {
@MockitoBean TaxCalculator taxCalculator; // Spring Boot 3.4+
}Before 3.4 the equivalent is @MockBean, which is deprecated later. Without either, the controller's dependency has no bean in the slice and the test fails with the same message as production.
Case 4: Conditional beans that silently disappear
@Bean
@ConditionalOnProperty(name = "billing.tax.enabled", havingValue = "true")
TaxCalculator taxCalculator() { return new DefaultTaxCalculator(); }Start with --debug or management.endpoint.conditions.enabled=true and read the condition evaluation report, which lists every @Conditional with matched or did-not-match and the reason.
Case 5: Generic beans and erasure
interface Handler<T> { void handle(T value); }
@Component class StringHandler implements Handler<String> {}
@Component class IntegerHandler implements Handler<Integer> {}Injecting Handler<String> resolves at runtime to Handler, so two candidates appear equal. Declare concrete subtypes or use @Qualifier with named beans.
Case 6: Kotlin classes that are final
A Kotlin class TaxCalculator without open cannot be proxied by Spring AOP, and depending on configuration the failure can surface as a missing candidate when the proxy creation is skipped. Mark the class open or use the all-open plugin for Spring stereotypes.
Common Compilation/Runtime Mistakes & Version Gotchas
javaxversusjakarta. Spring Boot 3 requiresjakarta.*; a class annotated withjavax.injectorjavax.annotationis never registered. The build succeeds and startup fails, which makes this easy to misread as a scan problem.- Duplicate dependencies from two BOMs. Two versions of the same library on the classpath can register neither bean. Run
mvn dependency:treeorgradle dependenciesand look for conflicting versions. @Configurationinside@Configuration. A nested config class declaredstaticis picked up; a non-static inner class can be skipped depending on scan order.- Constructor with too many parameters. Spring does not pick a constructor when there are several and none is annotated; add
@Autowiredto the intended one, or keep exactly one constructor. - Lazy initialization.
spring.main.lazy-initialization=truemoves the failure from startup to the first call, so a deployment looks healthy and then errors under load. - Proxy self-invocation. Calling a
@Transactionalmethod from within the same bean bypasses the proxy; the bean exists, but the behavior does not, which is a different bug with the same starting point in the log.
When the context fails during a build, capture the --debug output and filter the condition report; paste the JSON of any actuator conditions response into the JSON formatter to see which conditions failed. If configuration values gate the bean, inspect the active profile files with the env file viewer rather than guessing which profile CI uses. For comparing a working application property file with the failing one, the diff tool makes a one-character key change obvious.
Primary references: Spring Framework dependency injection and collaborators explains autowiring and qualifiers, and structuring your Spring Boot code documents the component scan base package rule.
Official references
primary documentationThe Java documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Java guides
All Java guidesMethod Scope in Java: How Local Variables Work
Understand how variables behave inside Java methods: local variable boundaries, block scope, parameter scope, shadowing, and lifetime implications.
Java: HikariPool connection is not available, request timed out
The HikariCP pool ran out of connections for the whole connectionTimeout. Read the counters, find leaks or slow queries, then size the pool.
Java: DateTimeParseException: Text could not be parsed
The formatter pattern and the input disagree. Check the index in the message, the locale, and whether the text needs a ZonedDateTime instead.
Java: java.net.BindException: Address already in use
The kernel refused the listening socket. Find the process holding the port, check the bound interface and privileged ports, then restart cleanly.
More in Java
All Java guidesThe guides filed next to this one in Java, in library order.