I’m trying to figure out if there is a way to configure Spring datasource using a single string that contains all credentials:
postgres://username:secret@localhost/somedb
By far I see that spring.datasource always requires username and password properties to be defined separately and url property to start with jdbc:.
Is there some other way to configure DB connection and use Postgres single string url?
BTW, this url works fine in Python/Django and GoLang.
Advertisement
Answer
As the documentation specifies, spring.datasource.url is the JDBC URL of the database.
The format of the JDBC url is driver specific, in your case Postgresql JDBC Driver.
You can specify the username and password of your database inside the JDBC url as connection properties. This is the general format:
jdbc:postgresql://host:port/database?properties
So, in your case: jdbc:postgresql://localhost/somedb?user=username&password=secret