i am following this https://spring.io/guides/gs/accessing-data-mysql/ guide to connect mysql db to spring boot project
but getting following error when running the a
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>
Update the pom.xml
file with DB version and the database:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
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>
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.
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.
Maybe you missing MySQL connector dependency so add it into dependencies tag on pom.xml file and run the project again. It may fix your problem.
`<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> `