Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Spring Boot cannot configure a DataSource for PostgreSQL

ErrorFailed 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.

  • Applies to Spring Boot 3.5, Spring Boot 4.0, PostgreSQL JDBC driver 42.x, Java 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 postgresql
  2. 2Match what you see, then jump to its fix

    1. 1The failure message says the 'url' attribute is not specifiedspring.datasource.url is missing from the configuration Spring readsFix
    2. 2Failed to determine a suitable driver class, or a class not found for org.postgresql.DriverThe PostgreSQL JDBC driver is not on the classpathFix
    3. 3The URL starts with postgres:// or postgresql:// instead of jdbc:postgresql://The JDBC URL does not follow the PostgreSQL formatFix

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*.yml

2Fix

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=dbpass

3Verify

Restart the app and watch for the pool starting instead of the failure.

java -jar target/app.jar

Confirmed by docs.spring.io

Did this fix it?

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 postgresql

2Fix

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 postgresql

Confirmed by jdbc.postgresql.org

Did this fix it?

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/mydb

3Verify

Restart the app and confirm the connection pool starts.

java -jar target/app.jar

Confirmed by jdbc.postgresql.org

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.