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.
Failed to configure a DataSource: 'url' attribute is not specified and no embedded
datasource could be configured.
Reason: Failed to determine a suitable driver classCommon 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.
env:
SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/app
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: postgresUse 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.
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.