Spring Boot "Error creating bean with name" in CI
Spring began instantiating a bean and its factory method or constructor threw. The message names the bean; the nested "Caused by" is the exception you must actually fix.
What this error means
Context fails with "Error creating bean with name 'X'" (a BeanCreationException) followed by a Caused-by chain such as an SQL error, an IllegalState, or a connection failure.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'entityManagerFactory' defined in class path resource
[.../JpaBaseConfiguration.class]: ... Caused by: org.postgresql.util.PSQLException: Connection refusedCommon causes
The bean depends on an unavailable resource
A DataSource, Kafka broker, or Redis the bean opens at startup is not reachable in CI, so construction throws.
A configuration property is wrong or missing
A value the bean needs (URL, credentials, path) is unset or malformed in the CI profile.
How to fix it
Fix the nested Caused-by
- Read the innermost exception under the bean creation error.
- Resolve that resource or property (start the service, set the value).
- Re-run; the BeanCreationException disappears once the resource is available.
Provide the resource the bean needs in CI
Add the service container or Testcontainers and wire its URL so the bean can construct.
services:
postgres:
image: postgres:16
env: { POSTGRES_PASSWORD: postgres }
ports: ['5432:5432']How to prevent it
- Ensure every eager bean has its resource available at startup in CI.
- Keep CI properties complete so beans do not construct with missing values.
- Read the Caused-by chain rather than the outer bean name.