Skip to content
Latchkey

Spring Boot "Failed to configure a DataSource: url attribute is not specified" in CI

Spring Boot auto-configured a DataSource, found no spring.datasource.url and no embedded database (H2/HSQL/Derby) on the classpath, so it cannot build a connection pool and fails startup.

What this error means

Startup or @SpringBootTest fails with "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured". It passes locally where a DB or H2 is present.

Spring Boot
Failed to configure a DataSource: 'url' attribute is not specified and no embedded
datasource could be configured.

Reason: Failed to determine a suitable driver class

Common causes

No spring.datasource.url in the CI profile

Local runs read a URL from application-local.properties or an IDE run config that CI does not have, so the runner sees no URL.

No embedded DB and no service container

H2 is not on the test classpath and no Postgres/MySQL service or Testcontainers URL is provided, so auto-config has nothing to connect to.

How to fix it

Point the DataSource at the CI service

Set the URL, username, and password via env vars that map to spring.datasource.* so the runner connects to the service container.

.github/workflows/ci.yml
env:
  SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/app
  SPRING_DATASOURCE_USERNAME: postgres
  SPRING_DATASOURCE_PASSWORD: postgres

Use an embedded H2 for pure unit tests

If tests do not need the real engine, add H2 to the test scope so an embedded DataSource is available.

build.gradle.kts
testImplementation("com.h2database:h2")

How to prevent it

  • Keep an application-ci.properties (or -test) with a concrete datasource URL.
  • Provide DB credentials as CI secrets or service-container env, never hardcoded.
  • Decide per test whether you need a real DB (Testcontainers) or H2.

Frequently asked questions

What causes ""Failed to configure a DataSource""?
Local runs read a URL from application-local.properties or an IDE run config that CI does not have, so the runner sees no URL.
How do I fix "Failed to configure a DataSource"?
Set the URL, username, and password via env vars that map to spring.datasource.* so the runner connects to the service container.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card