title: Cannot load driver class: com.mysql.cj.jdbc.Driver
body: <p>My Spring Boot Project trying connect to MYSQL database with driver <code>mysql-connector-java</code>.
  I have import newest mysql driver and <code>spring-boot-starter-data-jpa</code></p>
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>I have configured database connection in <code>application.properties</code> file</p>
  <pre><code>spring.jpa.hibernate.ddl-auto=update
  spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
  spring.datasource.username=somethingfunny
  spring.datasource.password=somethingfunny
  spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
  #spring.jpa.show-sql: true
  </code></pre>
  <p>MYSQL version is 8.0.26</p>
  <p><a href="https://i.stack.imgur.com/XWpoJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XWpoJ.png" alt="enter image description here" /></a></p>
  <p>Spring boot version 2.6.2</p>
  <p><a href="https://i.stack.imgur.com/VkItX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VkItX.png" alt="enter image description here" /></a></p>
  <p>When run project with Intellij I get error</p>
  <blockquote>
  <p>Caused by: org.springframework.beans.BeanInstantiationException:
  Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory
  method 'dataSource' threw exception; nested exception is
  java.lang.IllegalStateException: Cannot load driver class:
  com.mysql.cj.jdbc.Driver  at
  org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
  ~[spring-beans-5.3.14.jar:5.3.14]     at
  org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
  ~[spring-beans-5.3.14.jar:5.3.14]     ... 35 common frames omitted Caused
  by: java.lang.IllegalStateException: Cannot load driver class:
  com.mysql.cj.jdbc.Driver  at
  org.springframework.util.Assert.state(Assert.java:97)
  ~[spring-core-5.3.14.jar:5.3.14]  at
  org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:241)
  ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]  at
  org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:193)
  ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]  at
  org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48)
  ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]  at
  org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90)
  ~[spring-boot-autoconfigure-2.6.2.jar:2.6.2]  at
  java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
  Method) ~[na:na]  at
  java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  ~[na:na]  at
  java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  ~[na:na]  at
  java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
  at
  org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
  ~[spring-beans-5.3.14.jar:5.3.14]     ... 36 common frames omitted</p>
  </blockquote>
  <p>I have refered the post about <a href="https://stackoverflow.com/questions/50671681/cannot-load-driver-class-com-mysql-jdbc-driver-spring-boot">Cannot load driver class: com.mysql.jdbc.Driver</a> (NOT com.mysql.cj.jdbc.Driver), I cannot apply for my project because my project get error when using <code>com.mysql.cj.jdbc.Driver</code> but not <code>com.mysql.jdbc.Driver</code>.</p>
  <p>I also refered this post <a href="https://stackoverflow.com/questions/54641439/cannot-load-driver-class-com-mysql-cj-jdbc-spring-boot">Cannot load driver class: com.mysql.cj.jdbc.Driver</a>. But i can not find correct answer(the answer is marked corrected) for this error.</p>
  <p>How to fix this error ?</p>