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.
Spring Boot
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.
.github/workflows/ci.yml
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.
Related guides
Spring Boot "UnsatisfiedDependencyException" in CIFix org.springframework.beans.factory.UnsatisfiedDependencyException in CI - a bean could not be created beca…
Spring Boot "Connection refused" to Postgres/MySQL in CIFix Spring Boot "Connection refused" to a Postgres or MySQL service container in CI - the app started before…
Spring Boot "ApplicationContextException: Unable to start web server" in CIFix org.springframework.context.ApplicationContextException "Unable to start web server" in CI - the servlet…