Hello,

Trying to do: spring.datasource.url=jdbc:mysql://${server.address}:${server.port}/foobar?createDatabaseIfNotExist=true&useSSL=true&serverTimezone=UTC&useLegacyDatetimeCode=false

But I am not allowed. Can you update the documentation to say that this is not allowed or fix this, please? Both "server.address" and "server.port" have been set in the properties file, and no matter where I put the datasource url (top / bottom of the file) it can never fetch the already defined properties. Both "server.address" and "server.port" can be fetched properly in classes with @Value. Just cannot get datasource to get it in the properties file.

Part of the given error: "com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.20.jar:8.0.20] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.20.jar:8.0.20] at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.20.jar:8.0.20]"...

Comment From: kedar-joshi

From the exception, it seems that database isn't accessible. Are you sure that server address and server port can be reached ?

I am able to successfully configure database using property placeholders -

server-host = localhost
server-port = 5432
spring.datasource.url = jdbc:postgresql://${server-host}:${server-port}/postgres
spring.datasource.username = postgres
spring.datasource.password = password

Comment From: Adriansun

server.address=127.0.0.1 server.port=8443

spring.datasource.url=jdbc:mysql://${server.address}:${server.port}/squareit?createDatabaseIfNotExist=true&useSSL=true&serverTimezone=UTC&useLegacyDatetimeCode=false

Does not work. Observe that your host and port is with a "-", whilst I am using the defaults which has a "." between them. Might be something with that.

Extra: Using Spring Boot Starter Parent: 2.3.1.RELEASE. ...if that would help, somehow...

Edit: changed "has a "-" to "with a "-".

Comment From: kedar-joshi

It's successful with . separated configuration as well -

server.host = localhost
server.port = 5432
spring.datasource.url = jdbc:postgresql://${server.host}:${server.port}/postgres
spring.datasource.username = postgres
spring.datasource.password = password

Does connecting without placeholders work ?

Curious, normally MySQL doesn't run on port 8443, are you sure these details are correct ?

Comment From: Adriansun

This is so odd.

_1. Why would my port of choice matter? _2. The project works as it should with "spring.datasource.url=jdbc:mysql://localhost:3306/foobar?createDatabaseIfNotExist=true&useSSL=true&serverTimezone=UTC&useLegacyDatetimeCode=false". Where "foobar" has been replaced with the real database/schema name.

If you would like to debug this with me then would you like to do a sharescreen in google hangouts?

Comment From: kedar-joshi

The project works as it should with "spring.datasource.url=jdbc:mysql://localhost:3306

Shouldn't you be setting server.port=3306 instead of server.port=8443 then ?

Comment From: Adriansun

I found the problem. I have several properties files and lo and behold: there was a mismatch with the names. That is why it did not work. Problem resolved. Sorry for wasting your time and thank you for your help.

Comment From: wilkinsona

Thanks for helping out, @kedar-joshi.