【问题标题】:Failed to configure a DataSource: 'url' attribute is not specified未能配置数据源:未指定“url”属性
【发布时间】:2019-10-31 15:41:10
【问题描述】:

我是 kotlin 的 Spring Boot 新手。 应用程序启动时出现错误。 我一直在 Stackoverflow 的其他答案中寻求各种解决方案。

但没有答案给我没有解决方案。

***************************
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

我的application.properties 配置如下。

spring.datasource.url=jdbc:mysql://localhost/db_name
spring.datasource.username=db_user
spring.datasource.password=db_pass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

build.gradle.kts 正在关注。

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.2.0.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    war
    kotlin("jvm") version "1.3.50"
    kotlin("plugin.spring") version "1.3.50"
    kotlin("plugin.jpa") version "1.3.50"
}
group = "jp.co.blowfish.springboot"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
val developmentOnly by configurations.creating
configurations {
    runtimeClasspath {
        extendsFrom(developmentOnly)
    }
}
repositories {
    mavenCentral()
}
dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    runtimeOnly("mysql:mysql-connector-java")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
}
tasks.withType<Test> {
    useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

我不知道出了什么问题。

【问题讨论】:

    标签: spring-boot kotlin


    【解决方案1】:

    缺少port of Mysql,默认为3306

      spring.datasource.url=jdbc:mysql://localhost:3306/db_name`
    

    application.properties 位于resources 文件夹中。

    【讨论】:

    • 我按照你说的添加了端口。但是它不起作用。
    猜你喜欢
    • 2019-10-20
    • 2023-02-07
    • 2019-09-12
    • 2019-03-16
    • 2018-12-15
    • 2020-05-31
    • 2023-02-21
    • 2020-04-26
    • 2022-07-21
    相关资源
    最近更新 更多