Ive just started a fresh Spring project after a long time, and Im not sure exactly what is there that I cannot make a simple configuration work.
I started with something simple, like a DB connection, like this:
spring:
datasource:
platform: postgres
host: jdbc:postgresql://localhost
port: 54322
database: 123
username: abc
password: asd
I only have the @SpringBootApplication
annotation, so, Im not configuring anything manually.
However, when I run this, it fails by not finding enough DB info.
My db dependencies
implementation 'org.postgresql:postgresql:42.1.4'
implementation 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.postgresql:postgresql'
Any idea why is this?
It works when I take datasource
outside of the spring:
tag
CodePudding user response:
spring: datasource: platform: postgres host: jdbc:postgresql://localhost port: 54322 database: 123 username: abc password: asd
You've to adjust the level for the properties.
spring:
datasource:
platform: postgres
host: jdbc:postgresql://localhost
port: 54322
database: 123
username: abc
password: asd
CodePudding user response:
As you say you are using spring boot since a long time.
The properties you reference (.platform
) are for Spring Boot 1.x (e.g.).
But the most recent version is 2.x, the properties changed slightly. Check the new reference documentation here: https://docs.spring.io/spring-boot/docs/2.7.0/reference/html/data.html#data.sql.datasource.configuration
For postgres jdbc url check https://jdbc.postgresql.org/documentation/80/connect.html.
spring:
datasource:
# platform is auto-detected now
url: jdbc:postgresql://localhost:54332/123
username: abc
password: asd
It does work if you move it out of the spring "tag" because Spring Boot then configures an ephermal in-memory database.