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
- Annotate the class or add an
@Beanmethod that returns the required type. - Ensure it is under the application base package or add
@ComponentScan. - For tests,
@Importthe config or add@MockBeanof 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
Spring Boot "NoSuchBeanDefinitionException" in CIFix org.springframework.beans.factory.NoSuchBeanDefinitionException in CI - Spring has no bean of the require…
Spring Boot "UnsatisfiedDependencyException" in CIFix org.springframework.beans.factory.UnsatisfiedDependencyException in CI - a bean could not be created beca…
Spring Boot wrong spring.profiles.active in CIFix Spring Boot picking the wrong spring.profiles.active in CI - the runner loads dev/prod config instead of…