Java Spring boot 无法从数据源(mysql)确定 jdbc url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51379680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:06:17  来源:igfitidea点击:

Spring boot unable to determine jdbc url from datasouce (mysql)

javamysqlspringspring-bootspring-data-jpa

提问by Adrian Pascu

I am trying to load a MySQL database into a spring boot application but when I start the application I am getting those error messages:

我正在尝试将 MySQL 数据库加载到 Spring Boot 应用程序中,但是当我启动应用程序时,我收到以下错误消息:

2018-07-17 13:46:31.426 WARN 2120 --- [ restartedMain] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasource

2018-07-17 13:46:31.426 WARN 2120 --- [ restartedMain] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasource

org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection: 'url' not set

org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection: 'url' not set

Although I have set the url property in application.properties: spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase

虽然我已经将 url 属性设置为application.propertiesspring.datasource.url=jdbc:mysql://localhost:3306/mydatabase

Can anyone help me figure this one out?

谁能帮我解决这个问题?

Edit: Here is my Main class:

编辑:这是我的主要课程:

package com.randomsoft.checkoff;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class CheckoffApplication {

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

采纳答案by Kathirvel Subramanian

can you try by removing @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})

您可以尝试删除 @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})

also try to add all below jdbc properties,

还尝试添加以下所有 jdbc 属性,

spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?verifyServerCertificate=false&useSSL=false&requireSSL=false
spring.datasource.username=<username>
spring.datasource.password=<password>
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update

回答by Andriy Br.

You should name property file: application.propertiesor application.yml

您应该命名属性文件:application.propertiesapplication.yml

回答by this_is_om_vm

just try to append this line in your config class

只需尝试在您的配置类中附加这一行

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})