Skip to content
Latchkey

Spring Boot "Field ... required a bean ... that could not be found" in CI

This is the FailureAnalyzer report for a missing autowire target. It names the field, the required type, and an Action listing why no bean matched, usually because nothing defines or scans it.

What this error means

Startup fails with "Field X in Y required a bean of type 'Z' that could not be found." plus an Action block suggesting you define such a bean.

Spring Boot
Description:

Field paymentClient in com.example.OrderService required a bean of type
'com.example.PaymentClient' that could not be found.

Action:

Consider defining a bean of type 'com.example.PaymentClient' in your configuration.

Common causes

The bean is not defined or not scanned

No @Component/@Bean produces the type, or it sits outside the scanned base package.

A conditional bean is off under the CI profile

A @ConditionalOnProperty or profile-guarded bean does not activate because the property or profile differs in CI.

How to fix it

Define or scan the bean

  1. Annotate the class or add an @Bean method that returns the required type.
  2. Ensure it is under the application base package or add @ComponentScan.
  3. For tests, @Import the config or add @MockBean of that type.
src/test/java
@MockBean PaymentClient paymentClient;

Turn on the condition in CI

Set the property or profile the conditional bean depends on.

.github/workflows/ci.yml
env:
  SPRING_PROFILES_ACTIVE: ci
  PAYMENT_CLIENT_ENABLED: 'true'

How to prevent it

  • Keep beans under the scanned base package or configure scanning explicitly.
  • Mirror production conditions/profiles in CI so conditional beans activate.
  • Mock external collaborators in slice tests rather than requiring real beans.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →