Unable to Connect Mysql container from a spring-boot application

At first sight everything looks okay with this compose file (you don’t define a data volume, but that’s something else). So this is a complicated one.
Just a guess, the reason could be the following: With mysql:latest you install MySQL 8.0 that uses ‘caching sha2 password’ as default authentication method. To connect to it you need a connector that is build with the most recent MySQL and not the MariaDB C libraries and supports this method. Read here about ‘caching_sha2_password as the Preferred Authentication Plugin’. Maybe your connector is not made for MySQL 8.0.
So what you could try is to use mysql:5.7 instead.