title: Failed to load driver class com.mysql.jdbc.Driver
body: <p>I am trying to run my Spring Boot backend with two profiles, one using H2 in memory database and the second one using MySQL. H2 database works just fine, but when I switch to MySQL I get</p>
  <pre><code>APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
  
      Property: driverclassname
      Value: com.mysql.jdbc.Driver;
      Origin: &quot;driverClassName&quot; from property source &quot;source&quot;
      Reason: Failed to load driver class com.mysql.jdbc.Driver; in either of HikariConfig class loader or Thread context classloader
  
  Action:
  
  Update your application's configuration
  </code></pre>
  <p>I have tried deleting .m2, reimporting, maven clean, compile, install and most of the things I could find on the internet, no success. The funny thing is that I have other project with MySQL database only, I had similar issue, but adding <strong>mysql-connector-java</strong> dependency solved it. I have no clue right now.</p>
  <p><strong>application.properties</strong></p>
  <pre><code>spring.profiles.active=@profilename@
  
  #H2 in memory database
  domain.datasource.type=H2
  domain.datasource.url=jdbc:h2:mem:store;MODE=MYSQL;
  domain.datasource.driver-class=org.h2.Driver
  domain.datasource.username=sa
  domain.datasource.password=
  domain.datasource.generate-dll=true
  </code></pre>
  <p><strong>application-local_mysql.properties</strong></p>
  <pre><code>spring.profiles.active=@profilename@
  
  #MySQL local database
  domain.datasource.type=MYSQL
  domain.datasource.url=jdbc:mysql://localhost:3600/store;
  domain.datasource.driver-class=com.mysql.jdbc.Driver;
  domain.datasource.username=store
  domain.datasource.password=store
  domain.datasource.generate-dll=false
  </code></pre>
  <p><strong>pom.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;sk.personal&lt;/groupId&gt;
      &lt;artifactId&gt;my-project&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;my-project&lt;/name&gt;
      &lt;description&gt;My personal project.&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.5.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;version&gt;2.0.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &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;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;local_h2&lt;/id&gt;
              &lt;properties&gt;
                  &lt;profilename&gt;local_h2&lt;/profilename&gt;
              &lt;/properties&gt;
              &lt;activation&gt;
                  &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
              &lt;/activation&gt;
          &lt;/profile&gt;
          &lt;profile&gt;
              &lt;id&gt;local_mysql&lt;/id&gt;
              &lt;properties&gt;
                  &lt;profilename&gt;local_mysql&lt;/profilename&gt;
                  &lt;maven.test.skip&gt;true&lt;/maven.test.skip&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <p><strong>DatasourceConfig.java</strong></p>
  <pre><code>import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.jdbc.DataSourceBuilder;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
  import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
  
  import javax.sql.DataSource;
  
  @Configuration
  public class DatasourceConfig {
  
      @Value(&quot;${domain.datasource.url}&quot;)
      private String url;
  
      @Value(&quot;${domain.datasource.username}&quot;)
      private String username;
  
      @Value(&quot;${domain.datasource.password}&quot;)
      private String password;
  
      @Value(&quot;${domain.datasource.type}&quot;)
      private String type;
  
      @Value(&quot;${domain.datasource.driver-class}&quot;)
      private String driverClass;
  
      @Bean
      public DataSource dataSource() {
          if (type.equals(&quot;MYSQL&quot;)) {
              return DataSourceBuilder
                      .create()
                      .username(username)
                      .password(password)
                      .url(url)
                      .driverClassName(driverClass)
                      .build();
          } else {
              EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
              return builder
                      .setType(EmbeddedDatabaseType.H2)
                      .build();
          }
      }
  }
  </code></pre>