๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
***************************
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).โก Quick Fix Works 80% of the time
Add the specific JDBC driver dependency (e.g., mysql-connector-j) to your pom.xml.
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>๐ง Why this Happens
Tap to expand the deep technical explanation
You added `spring-boot-starter-data-jpa` to your project, which triggers Spring Boot's auto-configuration to look for a database. However, you did not provide a specific JDBC driver dependency (like MySQL or PostgreSQL) in your `pom.xml`, and Spring Boot couldn't find an embedded database (like H2) to auto-configure.
The HITEC City Parking Spot Analogy:
It's like buying a car engine (JPA) but forgetting to buy fuel (the JDBC driver). The engine is ready, but it has nothing to run on.
๐ How to Reproduce Confirm this is your error
Create a new Spring Boot project. Add the 'Spring Data JPA' starter but DO NOT add the 'H2 Database' or 'MySQL Driver' dependencies. Add `spring.datasource.url=jdbc:mysql://localhost:3306/db` to properties. Run the app.
๐ ๏ธ Solutions (5 Ways to Fix)
Add the specific database driver dependency
๐ Use this when you want to connect to a real database (MySQL/Postgres).
Spring Boot needs the JDBC driver to know how to talk to your specific database.
<!-- pom.xml for MySQL -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>Add an embedded database dependency (H2)
๐ Use this for quick prototyping or learning without installing a real database.
Adding H2 allows Spring Boot to auto-configure a temporary in-memory database with zero configuration.
<!-- pom.xml -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>Explicitly specify the driver class name
๐ Use this if you have the driver dependency but Spring still can't detect it automatically.
Tell Spring exactly which driver class to load.
# application.properties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.DriverExclude DataSource Auto-Configuration
๐ Use this if you are building a non-database app but accidentally left JPA in the pom.
Tell Spring Boot to stop trying to configure a database entirely.
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class Application { ... }Fix YAML indentation
๐ Use this if you are using `application.yml` and are sure the driver is present.
If `driver-class-name` is not perfectly aligned under `datasource:`, Spring won't read it and will fail to determine the driver.
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
driver-class-name: com.mysql.cj.jdbc.Driver # Must be aligned perfectly๐ Version Notes
Standard auto-configuration failure.
Identical behavior, but auto-configuration is stricter about missing properties.
๐ก๏ธ How to Prevent This Next Time
Always add your database driver dependency (e.g., `mysql-connector-j`) at the exact same time you add the `spring-boot-starter-data-jpa` dependency.