Unable to connect mysql to spring boot project

Try to add mysql connector driver version and remove scope tag from:

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

com.zaxxer.hikari.HikariDataSource requires spring-boot-starter-data-jdbc dependency, so add it to your pom.xml:

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

It seems like the application may not be running with the correct classpath as it seem to be having difficulty locating the mysql driver. Are you trying to run the application through the IDE?

Try running the application via maven using the command line from the project's directory:

./mvnw spring-boot:run

If this works then it's a problem with the IDE, for some reason it's not providing the correct classpath when running your application. I'm not familiar with STS but in IntelliJ there are options like "auto import pom" to keep the IDE's view of the project in sync with the pom.


FYI, I encountered a similar problem when I changed my Spring Boot app from H2 to mySQL.

I was using Gradle (instead of Maven). I, too, was using STS.

I simply forgot to run Refresh Gradle Project after I added this to my build.gradle file:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    ...
    // Use MySQL Connector-J
    compile 'mysql:mysql-connector-java'

The problem went away after doing a "Refresh Gradle Project" and rebuilding/restarting my app.