2017-04-25 332 views
-1
@SpringBootApplication 
@Slf4j 
public class Starter { 

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

Applicaiton.yml无法加载驱动程序类:org.h2.Driver与springboot

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") 
} 

错误:

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 

任何想法我错过了什么?

我试图从yml文件中删除:driverClassName:org.h2.Driver 。没有工作。

试图修改build.gradle和版本H2 ..也没有工作。

+1

也许H2版本号在build.gradle? – Mario

+0

你会推荐你改变这个版本吗? – rayman

+0

没有特别推荐。举例来说,我目前正在使用“com.h2database:h2:1.4.194”,并没有任何问题。 – Mario

回答

0

尝试从application.yml中删除驱动程序名称。休眠应该选择能够从你的url中获取它

+0

删除。得到的原因:java.lang.ClassNotFoundException:org.h2.Driver – rayman

+1

看着DataSourceProperties方法,它就像是包装了一个classNotFoundError,这表明驱动程序没有正确地从依赖关系导入。检查你的图书馆,看看你是否能在那里找到它。你也可以尝试设置它来测试编译 – thejames42

+0

什么库?我向你展示了所有libs iam通过我的build.grade文件导入 – rayman

相关问题