Failed to auto-configure a DataSource 'spring.datasource.url' is not specified
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The error Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified means Spring Boot thinks your application needs a JDBC DataSource, but it does not have enough configuration to create one. The fix is not always “add a URL.” First determine why Boot is trying to configure a database at all.
Why Spring Boot Tries to Create a DataSource
Spring Boot auto-configures a DataSource when it sees JDBC- or JPA-related dependencies on the classpath. For example, if the project includes spring-boot-starter-data-jpa and a database driver, Boot assumes you want database access.
If the application lacks the required connection properties, startup fails.
Typical required properties look like this:
If you really want a database, adding those properties is the correct fix.
Fix 1: Configure the Database Properly
For a real JDBC-backed application, put the datasource configuration in application.properties or application.yml.
Then make sure the actual driver dependency is present and the database is reachable.
Fix 2: Use an Embedded Database for Local Development
If you only need a quick local database, add an embedded database dependency such as H2. Spring Boot can auto-configure that without a manually supplied URL in many development setups.
Example dependency in Maven:
This is useful for demos, tests, and simple local runs.
Fix 3: Remove Unneeded Database Starters
Sometimes the real answer is that the application does not need a datasource at all. If you added spring-boot-starter-data-jpa or another JDBC-oriented starter by accident, remove it.
For example, a REST API that does not talk to a database should not carry JPA dependencies just because they were copied from another project.
This is often the cleanest solution.
Fix 4: Exclude DataSource Auto-Configuration
If the dependency must remain but you do not want Boot to create a datasource in this application, exclude the auto-configuration explicitly.
This tells Boot not to create a DataSource automatically.
How to Decide Which Fix Is Right
Ask one question first: should this application have a relational datasource?
- If yes, configure
spring.datasource.*correctly - If only for local testing, consider H2
- If no, remove the database starter or exclude datasource auto-configuration
That decision avoids treating every startup error as a property typo.
It is also worth checking the active Spring profile. A common setup keeps datasource properties in a profile-specific file such as application-dev.yml or application-prod.yml. If the expected profile is not active, Boot starts without the database settings you thought were present.
Common Pitfalls
A common mistake is adding the database driver but forgetting the URL, username, or password.
Another mistake is copying spring-boot-starter-data-jpa into a project that does not need relational persistence. That makes Boot try to configure a datasource for no reason.
A third issue is excluding datasource auto-configuration when the application actually needs a database later. That hides the real configuration problem instead of solving it.
Summary
- The error means Spring Boot expects to create a JDBC datasource but lacks enough configuration
- If the app needs a database, add the correct
spring.datasource.*properties - For simple local development, an embedded database such as H2 can be enough
- If the app does not need a datasource, remove the starter or exclude the auto-configuration
- Fix the cause of Boot's expectation, not just the symptom of the startup error

