The Situation
You added a JPA or JDBC dependency, hit run, and got this on startup:
***************************
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 class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Spring Boot spotted spring-boot-starter-data-jpa or spring-boot-starter-jdbc on the classpath and tried to wire up a DataSource bean. No URL, no driver โ nothing to work with, so it bailed immediately.
Why This Happens
Database-related starters trigger Spring Boot's auto-configuration. The moment it sees those on the classpath, it tries to build a DataSource bean. Without either a configured spring.datasource.url (MySQL, PostgreSQL, etc.) or an embedded database (H2, HSQL, Derby) to spin up automatically, the startup fails.
Three situations that cause this most often:
- You copied a dependency from another project but left behind the
application.propertiesconfig - You're building a new module and haven't set up the database yet
- The datasource config exists, but it's in the wrong file or tied to a Spring profile that isn't active
Quick Fix โ Pick What Fits Your Situation
Option 1: Add the Database URL to application.properties
Connecting to a real database? Add these lines and you're done:
# application.properties
# MySQL example
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=yourpassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# PostgreSQL example
# spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
# spring.datasource.username=postgres
# spring.datasource.password=yourpassword
The matching JDBC driver also needs to be in your dependencies. For MySQL in Maven:
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
Option 2: Add H2 for Local Development / Testing
No real database yet? H2 runs entirely in memory โ zero setup required. Just add the dependency:
<!-- Maven -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
# Gradle
runtimeOnly 'com.h2database:h2'
Spring Boot auto-configures the H2 database with no extra properties needed. Works great for unit tests and early-stage development where you don't want to spin up a full DB server.
Option 3: Exclude DataSource Auto-Configuration
Sometimes the dependency crept in as a transitive dep and your app doesn't actually use a database. Or you're wiring the datasource manually in code. Either way, tell Spring Boot to back off:
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class
})
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
Prefer properties? Same effect:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Common Trap: Wrong Spring Profile Active
Many teams split config across profile files: application-dev.properties, application-prod.properties, and so on. The datasource URL lives in one of those files. But Spring Boot only reads the base application.properties when no profile is active โ and finds nothing.
Check which profile is running, or set it explicitly in your properties:
spring.profiles.active=dev
From the command line:
java -jar myapp.jar --spring.profiles.active=dev
For application.yml Users
YAML config looks like this:
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: yourpassword
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
YAML is indentation-sensitive. One misplaced space silently breaks your config โ no obvious error, just missing values at runtime. Paste your config into ToolCraft's YAML โ JSON Converter to catch syntax issues before they bite you. It runs entirely in the browser, so no credentials leave your machine.
Verify the Fix
Restart the app. A healthy startup looks like this:
HikariPool-1 - Starting...
HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@...
HikariPool-1 - Start completed.
Started MyApplication in 3.421 seconds (process running for 3.8)
No APPLICATION FAILED TO START block. That's your green light.
Want harder proof? Add a smoke test that actually opens a connection:
@SpringBootTest
class DataSourceTest {
@Autowired
DataSource dataSource;
@Test
void connectionShouldSucceed() throws Exception {
try (Connection conn = dataSource.getConnection()) {
assertThat(conn.isValid(1)).isTrue();
}
}
}
Prevention Tips
- Keep an
application-dev.propertieswith a working local DB config (or H2 fallback) so new developers can run the app without any setup on day one - In CI pipelines, pin
--spring.profiles.active=testand use H2 or Testcontainers โ keeps tests isolated and reproducible across machines - Validate YAML before committing. The converter linked above catches indentation bugs that are invisible in most text editors
- Audit
pom.xmlorbuild.gradleperiodically โ transitive dependencies quietly pull inspring-boot-starter-data-jpamore often than you'd expect

