Spring Boot cannot configure a DataSource for PostgreSQL
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Short answer
Spring Boot builds a pooled DataSource only when it has a JDBC URL and a loadable driver. With no spring.datasource.url it looks for an embedded database, finds none, and stops. Set the URL in a properties file Spring really reads, put the org.postgresql driver on the classpath, and use the jdbc:postgresql://host:port/database form.
Fix it fast
1Find out which cause you have
Check which spring.datasource values your project really contains, and whether the driver jar is in the build.
grep -rn "spring.datasource" src/main/resources/ mvn dependency:tree | grep -i postgresql2Match what you see, then jump to its fix
- 1
The failure message says the 'url' attribute is not specifiedspring.datasource.url is missing from the configuration Spring readsFix - 2
Failed to determine a suitable driver class, or a class not found for org.postgresql.DriverThe PostgreSQL JDBC driver is not on the classpathFix - 3
The URL starts with postgres:// or postgresql:// instead of jdbc:postgresql://The JDBC URL does not follow the PostgreSQL formatFix
- 1
What does the error look like?
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.Failed to determine a suitable driver class
Cause 1 of 3
spring.datasource.url is missing from the configuration Spring reads
1Check
Spring Boot's documentation says you should set at least spring.datasource.url; otherwise it tries to auto-configure an embedded database. A misnamed file, or a key spelled differently, leaves the URL unset.
ls src/main/resources/
grep -rn "datasource" src/main/resources/application*.properties src/main/resources/application*.yml2Fix
Put the three properties in application.properties (or the active profile's file) and keep the key names exact.
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=dbuser
spring.datasource.password=dbpass3Verify
Restart the app and watch for the pool starting instead of the failure.
java -jar target/app.jarConfirmed by docs.spring.io
Cause 2 of 3
The PostgreSQL JDBC driver is not on the classpath
1Check
Spring Boot checks that a valid Driver class can be loaded before it creates a pooled DataSource. The PostgreSQL driver is a separate artifact, org.postgresql:postgresql, and its jar must be on the classpath at runtime.
mvn dependency:tree | grep -i postgresql
# Gradle: ./gradlew dependencies --configuration runtimeClasspath | grep -i postgresql2Fix
Add the driver as a runtime dependency. Spring Boot manages the driver version, so the dependency needs no version number.
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>3Verify
Rebuild and check that the jar now appears in the dependency tree.
mvn clean package && mvn dependency:tree | grep -i postgresqlConfirmed by jdbc.postgresql.org
Cause 3 of 3
The JDBC URL does not follow the PostgreSQL format
1Check
The driver's documentation gives the format jdbc:postgresql://host:port/database, with the host defaulting to localhost and the port to 5432. Connection strings copied from a hosting dashboard often miss the jdbc: prefix.
grep -rn "datasource.url" src/main/resources/2Fix
Rewrite the value in the documented form. You do not need spring.datasource.driver-class-name for this driver: Spring Boot works it out from the URL.
spring.datasource.url=jdbc:postgresql://db.example.com:5432/mydb3Verify
Restart the app and confirm the connection pool starts.
java -jar target/app.jarConfirmed by jdbc.postgresql.org
How do I stop it coming back?
- Keep database settings in environment-specific files and confirm which profile is active at startup.
- Add one integration test that starts the context against a real PostgreSQL instance, so a missing driver or URL fails in CI.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Databases
H2 in PostgreSQL mode still behaves differently from PostgreSQL
Names or null ordering differ from PostgreSQL in test results
H2 compatibility modes are switched on in the JDBC URL and cover only a small part of the differences between databases.
4 causes, each with a fixDatabases
Hibernate insert fails: column is of type bit but expression is of type boolean
ERROR: column "active" is of type bit but expression is of type boolean
PostgreSQL has a real boolean type and a separate bit type, and it will not convert one to the other on insert.
3 causes, each with a fixDatabases
Spring Boot stops at startup with flywayInitializer failing
Caused by: org.flywaydb.core.api.FlywayException
flywayInitializer is the bean that runs your migrations at startup, so any migration problem surfaces as its BeanCreationException.
4 causes, each with a fixDatabases
Spring Boot cannot use the PostgreSQL JDBC URL it was given
java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl
The message means the URL string handed to the driver is not a PostgreSQL JDBC URL.
3 causes, each with a fixDatabases
Spring Boot JPA cannot find the PostgreSQL table it maps to
ERROR: relation "telephone_number" does not exist
Spring Boot maps an entity to a lowercase snake_case table name and creates tables on its own only for embedded databases.
2 causes, each with a fixDatabases
Flyway cannot handle the PostgreSQL URL after upgrading to Flyway 10 or newer
No database found to handle jdbc:postgresql://localhost:5432/app
Since Flyway 10, each database has its own module.
4 causes, each with a fix