Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load driver class: com.mysql.jdbc.Driver Spring

Tags:

spring

spring.freemarker.cache:false   spring.datasource.url=jdbc:mysql://localhost/mydb spring.datasource.username=user spring.datasource.password=pass spring.datasource.driver-class-name=com.mysql.jdbc.Driver 

im getting this error even with the driver-class-name difined

java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:153) ~[spring-boot-autoconfigure-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:119) ~[spring-boot-autoconfigure-1.3.0.M5.jar:1.3.0.M5] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60] at ......

and it goes on

like image 471
voidcurser Avatar asked Oct 14 '15 11:10

voidcurser


People also ask

Could not load driver com mysql jdbc driver?

Driver occurs if there is a disparity between mysql driver class, mysql driver jar version and mysql database version. The java application attempts to load a driver class from the mysql database driver jar. If the driver class is unable to load, the exception Cannot load driver class: com.


1 Answers

If you're using Maven, add this to your pom.xml:

(Recommended) For MySQL 5.6, 5.7, 8.x and Java >= 8 use;

<dependency>     <groupId>mysql</groupId>     <artifactId>mysql-connector-java</artifactId>     <version>8.0.25</version> </dependency> 

(Legacy) For MySQL <= 5.5 or Java <= 7 or JDBC < 4.2 use;

<dependency>     <groupId>mysql</groupId>     <artifactId>mysql-connector-java</artifactId>     <version>5.1.49</version> </dependency> 

More details on Connector/J versions

like image 108
bekce Avatar answered Sep 18 '22 15:09

bekce