【问题标题】:Gradle - Failed to determine a suitable driver classGradle - 无法确定合适的驱动程序类
【发布时间】:2019-05-27 00:17:58
【问题描述】:

我是 Spring-boot 的新手,我想使用 Eclipse、Spring 和 Gradle 创建应用程序。创建“Spring Starter Project”后,我无法运行该应用程序。痕迹说:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-30 19:26:36.732 ERROR 3483 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

这是我的“build.gradle”文件:

buildscript {
    ext {
        springBootVersion = '2.1.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    implementation('org.springframework.boot:spring-boot-starter-actuator')
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    implementation('org.springframework.boot:spring-boot-starter-web')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

  • 发布您的pom.xml
  • 请发布您的 application.properties(或 .yml)
  • 我在你的类路径中看不到 H2。我所看到的只是 3 个弹簧靴启动器。
  • 你试过这些答案吗?
  • 是的,目前没有一个对我有用。我没有尝试拥有 h2 数据库,我只是添加一个可以解决问题。因此,即使我尝试将依赖项 implementationcompile 添加到 gradle 依赖项,它也不起作用。

标签: java spring eclipse spring-boot gradle


【解决方案1】:

在我的情况下,文件 application.properties 位于 src/main/resources/static,将其移动到 src/main/resources 解决了错误

【讨论】:

    【解决方案2】:

    在您的 gradle 依赖项中添加 implementation('com.h2database.h2')。 默认情况下,spring boot 自动使用这个 db url "jdbc:h2:mem:testdb" 配置 h2

    【讨论】:

      猜你喜欢
      • 2019-03-18
      • 2022-01-19
      • 2021-11-22
      • 2021-09-12
      • 2023-02-04
      • 2019-12-06
      • 2019-05-10
      • 2018-12-26
      • 2020-10-23
      相关资源
      最近更新 更多