web-dev-qa-db-fra.com

Impossible de charger la classe de pilote: org.h2.Driver avec Spring Boot

@SpringBootApplication
@Slf4j
public class Starter {

    public static void main(String[] args) {
        SpringApplication.run(Starter.class, args);
    }
}

Applicaiton.yml

spring:
  profiles: default
  allowedIPPattern: 127.0.0.1|0:0:0:0:0:0:0:1|::1
  jpa.hibernate.ddl-auto: validate
  datasource:
    driverClassName: org.h2.Driver
    url: jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;INIT=create schema if not exists \"public\"\; SET SCHEMA public;

build.gradle:

buildscript {

    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    ext.ver = [
            'springboot' : '1.5.3.RELEASE',
            'slf4j': '1.7.12'
    ]

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${ver.springboot}")
        classpath "se.transmode.gradle:gradle-docker:1.2"
    }
}

group 'com.mycompany'
version '1.0-SNAPSHOT'

apply plugin: 'Java'
apply plugin: 'org.springframework.boot'



repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile("org.springframework.boot:spring-boot-starter-web:${ver.springboot}")
    compile ('org.projectlombok:lombok:1.16.6')
    compile("org.springframework.boot:spring-boot-starter-actuator")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    runtime("mysql:mysql-connector-Java:5.1.38")
    runtime("org.flywaydb:flyway-core")
    compile("com.h2database:h2")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
}

erreur:

Caused by: Java.lang.IllegalStateException: Cannot load driver class: org.h2.Driver
    at org.springframework.util.Assert.state(Assert.Java:70) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.Java:231) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.Java:183) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.Java:42) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat.dataSource(DataSourceConfiguration.Java:56) ~[spring-boot-autoconfigure-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_73]
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:1.8.0_73]
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.8.0_73]
    at Java.lang.reflect.Method.invoke(Method.Java:497) ~[na:1.8.0_73]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.Java:162) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    ... 55 common frames omitted

Une idée de ce qui me manque?

J'ai essayé de supprimer: driverClassName: org.h2.Driver du fichier yml. n'a pas fonctionné.

essayé de modifier build.gradle et la version en H2 .. n'a pas fonctionné non plus.

9
rayman

essayez de supprimer le nom du pilote de votre application.yml. hibernate devrait choisir de pouvoir le récupérer dans votre URL

4
thejames42