Skip to content
Advertisement

The dreaded Java SpringBoot app not connecting to MySQL with Docker-compose java.net.ConnectException: Connection refused

I have been struggling with the following issue – the dreaded Java SpringBoot app not connecting to MySQL with docker compose exceptions:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

JDBCConnectionException: Unable to open JDBC Connection for DDL execution

java.net.ConnectException: Connection refused

The app works fine on its own, but it can’t seem to connect to mysql once I get it in Docker. I think I have all parameters correct, what am I missing?

  • Platform:
JavaScript

Here is the whole codebase: Codebase

Run with command:

JavaScript

My docker-compose.yml (The commented out stuff is things I tried):

JavaScript

My setup.sql script:

JavaScript

My dockerfile:

JavaScript

My application.properties file:

JavaScript

Here are the exception messages:

JavaScript

Advertisement

Answer

To fix it you just need to change parameter spring.datasource.jdbc-url to spring.datasource.url and connection string to jdbc:mysql://genesysmysql:3306/db_example?useSSL=false&allowPublicKeyRetrieval=true&autoReconnect=true. Your connection string has an error.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement