【发布时间】:2018-12-25 01:19:36
【问题描述】:
我正在尝试将 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
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
虽然我已经在application.properties 中设置了url 属性:spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
谁能帮我解决这个问题?
编辑:这是我的主要课程:
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);
}
}
【问题讨论】:
-
您的文件是命名为 application.property 还是 application.properties?
-
。特性。感谢您指出这一点
-
由于您通过“@EnableAutoConfiguration”排除属性禁用自动配置类,您可以尝试“@Configuration”而不是“@SpringBootApplication”
-
@Sri9911 该注释是一个建议,因此我可以将其删除。使用“@Configuration”而不是“@SpringBootApplication”会混淆我所有的 bean 声明、bean 依赖注入……所以这不是一个可行的选择
标签: java mysql spring spring-boot spring-data-jpa