Debug Spring Bean Wiring Problems With Actuator and Logs
Debug Spring bean wiring: read the failure analysis, list beans with Actuator, use the conditions report and turn on bean creation logging.

Spring wiring errors are explicit, and the cause is usually one of five things. A short routine finds it faster than reading code.
Read the failure
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in dev.javahacks.OrderService required a bean of type
'dev.javahacks.PaymentGateway' that could not be found.
Action:
Consider defining a bean of type 'dev.javahacks.PaymentGateway' in your configuration.It says which class (OrderService), which parameter, and which type is missing. Other messages are covered in NoSuchBeanDefinitionException and NoUniqueBeanDefinitionException. Read the root cause at the bottom of the chain ("Caused by").
Is the bean in the context
With Actuator:
management.endpoints.web.exposure.include=beans,conditions,envcurl localhost:8080/actuator/beans | jq '.contexts[].beans | to_entries[] | select(.value.type | test("PaymentGateway")) | .key'If the context started, this lists beans of that type with their source (class or @Bean method) and their dependencies. If it did not start, run the check in a test:
@SpringBootTest
class WiringTest {
@Autowired ApplicationContext context;
@Test
void listsGateways() {
System.out.println(Arrays.toString(context.getBeanNamesForType(PaymentGateway.class)));
}
}Why a bean is missing
| Check | How |
|---|---|
| Scanned? | Is the class under the package of @SpringBootApplication? See component scanning |
| Annotated? | @Component, @Service or a @Bean method |
| Profile? | @Profile("prod") on the class, and which profiles are active (/actuator/env) |
| Conditional? | @ConditionalOnProperty, @ConditionalOnClass, check the conditions report |
| Excluded? | exclude on the application or spring.autoconfigure.exclude |
| Test slice? | @WebMvcTest and @DataJpaTest load only part of the context, see MockitoBean |
Printing the active profiles at startup: logging.level.org.springframework.boot.context.config=DEBUG shows config files and profile activation.
Why a bean appears twice
Two beans of one type and an injection point that does not say which: add @Primary, a @Qualifier, or inject by a parameter name that matches the bean name (needs -parameters). Find both with the beans endpoint. If a test configuration adds a second bean, use @MockitoBean to replace instead of adding. The resolution order is explained in Autowired, Qualifier and Primary.
Creation order and details
logging.level.org.springframework.beans.factory.support=DEBUG
logging.level.org.springframework.context.annotation=DEBUGThe first logs bean creation ("Creating shared instance of singleton bean ..."), and the second logs configuration class processing. The output is long, so redirect it to a file and search. For timing, use the startup endpoint described in the slow startup post.
Cycles
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| orderService defined in file [...]
↑ ↓
| paymentService defined in file [...]
└─────┘Boot rejects cycles by default. The real fix is in the design: extract the shared part, use events, or inject lazily as the last resort, see circular dependencies.
Proxy surprises
If a bean exists and the injection fails with a type mismatch, it may be a JDK proxy that implements an interface but not the class you inject by. Spring Boot defaults to class-based proxies, and old configuration may switch it. See the proxy rules in the Spring proxies article.
A habit that prevents most of it
Prefer constructor injection, so a missing bean fails at startup, not in the first request, and keep configuration classes small with explicit conditions. A smoke test that loads the full context in CI (@SpringBootTest with no mocks, or a startup test of the packaged app) finds wiring errors before deployment. The reasoning on injection styles is in constructor versus field injection.
Ask the context directly
When reading code does not settle it, query the container. A few lines in a test or a CommandLineRunner list what exists:
@Autowired
ApplicationContext ctx;
void dump() {
for (String name : ctx.getBeanNamesForType(PaymentGateway.class)) {
BeanDefinition def = ((ConfigurableApplicationContext) ctx)
.getBeanFactory().getBeanDefinition(name);
System.out.println(name + " -> " + def.getBeanClassName() + " from " + def.getResourceDescription());
}
}The output names each bean of that type with the class and the place that defined it. Zero lines means the bean is not registered, which sends the search to scanning and conditions. Two lines means there is ambiguity, which sends it to @Primary or a qualifier. The resource description names the configuration class or the file, so the second definition is easy to find.
Turn up the container's own logging
The bean factory logs what it creates and why, at DEBUG:
logging.level.org.springframework.beans.factory=DEBUG
logging.level.org.springframework.context.annotation=DEBUGThe output is long, so redirect it to a file and search for the bean name. The annotation package shows which classes were found by component scanning and which @Configuration classes were processed, and a class that never appears there is outside the scanned packages. Turn the logging off again, since it is expensive and noisy.
A test that stops the next break
A single test that loads the context fails the build when any wiring breaks, which is cheaper than a failed deploy:
@SpringBootTest
class ContextLoadsTest {
@Test
void contextLoads() {
}
}It starts the whole application, so it needs the test configuration to supply every property and external service that startup touches. Slice tests such as @WebMvcTest and @DataJpaTest load part of the context and fail faster on wiring that belongs to their layer. A project that has both catches most wiring errors before a person sees them.
The exceptions and what each says
| Exception | Meaning | First move |
|---|---|---|
NoSuchBeanDefinitionException | Nothing of that type or name is registered | Scanning, conditions, profile |
NoUniqueBeanDefinitionException | More than one candidate | @Primary, @Qualifier, or remove one |
UnsatisfiedDependencyException | A dependency of a bean could not be injected, wraps one of the above | Read the nested cause at the bottom |
BeanCurrentlyInCreationException | A constructor cycle | Break the cycle in the design |
BeanCreationException | The constructor or an init method threw | Read the Caused by chain for the real error |
BeanDefinitionOverrideException | Two definitions share a name | Rename one, avoid enabling overriding |
The wrapper exceptions are long, and the useful line is usually the last Caused by. The first line of the report names the bean that failed, and the last names why.
Bean overriding
Boot disables overriding of bean definitions by default, so two beans with the same name fail at startup. The property spring.main.allow-bean-definition-overriding=true turns it back on, and with it the order of definitions decides the winner, which changes with a classpath reorder. Use it only in tests that replace a bean on purpose, and prefer @MockitoBean for that. In production code, a duplicate name is a mistake to fix.
When the report is not enough
Some wiring problems have no clear message, such as a bean that exists but is the wrong one. The quickest way to see which instance was injected is to print its class and identity where it is used. A class name containing $$SpringCGLIB$$ shows a proxy, and a name of a different implementation than expected shows the wrong candidate was chosen. If two implementations exist, check which has @Primary and which qualifier the injection point names, and remember that parameter names are used as a fallback qualifier only when the code is compiled with the -parameters flag, which Boot's build plugins enable.
Remove the diagnostic print afterwards. A short test that asserts the type of the injected bean keeps the fix in place.
Where this does not apply
Runtime behaviour problems after startup, such as a transaction not applying, are not wiring failures. For @Transactional, see self-called methods. The reference is the Actuator beans endpoint, and the IoC container documentation describes resolution.


