Spring Boot "Failed to configure a DataSource: url attribute is not specified" - Fix in CI
Spring Boot tried to autoconfigure a DataSource but you gave it no spring.datasource.url and there is no embedded database (H2/HSQLDB/Derby) on the classpath for it to fall back to.
What this error means
Startup or a @SpringBootTest fails with Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. followed by an action suggesting you set the URL or add an embedded database.
***************************
APPLICATION FAILED TO START
***************************
Description:
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 JDBC URL is set in the CI profile
The local profile points at a real database but the CI run has no spring.datasource.url, so autoconfiguration has nothing to connect to.
No embedded database on the test classpath
Without H2/HSQLDB as a test dependency, Spring cannot fall back to an in-memory DataSource for the test context.
DataSource autoconfiguration loaded when it should not be
A test that does not need persistence still triggers DataSourceAutoConfiguration, demanding a URL it has no reason to provide.
How to fix it
Add an embedded database for tests
Put H2 on the test classpath so Spring autoconfigures an in-memory DataSource in CI.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>Set the datasource URL in the CI profile
If tests hit a real database (e.g. Testcontainers), provide the URL via the active profile or env.
# application-test.yml
spring:
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
driver-class-name: org.h2.DriverExclude DataSource autoconfig when persistence is not needed
For tests with no database, exclude the autoconfiguration so no URL is required.
@SpringBootTest
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
class NoDbTest { /* ... */ }How to prevent it
- Add H2 as a test dependency for any app that autoconfigures a DataSource.
- Keep a dedicated
testprofile with an explicit in-memory or Testcontainers URL. - Exclude
DataSourceAutoConfigurationin slices that do not touch persistence.