数据源配置异常
Posted 天河一粟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据源配置异常相关的知识,希望对你有一定的参考价值。
先上异常信息
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-31 18:53:44.137 ERROR 15044 --- [ 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).
针对如上异常原因有以下几点
-
数据源配置不对,需要在
application.properties
增加如下数据源,注意二选一# mysql数据库连接 spring boot 2.0(内置jdbc5驱动) #spring.datasource.driver-class-name=com.mysql.jdbc.Driver #spring.datasource.url=jdbc:mysql://localhost:3306/testdb?characterEncoding=utf-8&useSSL=false #spring.datasource.username=root #spring.datasource.password=root # mysql数据库连接 spring boot 2.1及以上(内置jdbc8驱动) spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/testdb?serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=root
-
在编译后的target目录中配置数据源的
application.properties
文件位置不对,把资源文件放到classes
目录下就好啦 -
使用
--spring.config.location
指定的配置文件的位置
① 命令方式
java -jar xxx.jar --spring.config.location=D:\\a\\b\\application.properties,D:\\a\\b\\logback-spring.xml
② idea开发工具参数形式
以上是关于数据源配置异常的主要内容,如果未能解决你的问题,请参考以下文章
mvn命令异常:An error has occurred in Javadoc report generation: Unable to find javadoc command异常已解决(代码片段
mvn命令异常:An error has occurred in Javadoc report generation: Unable to find javadoc command异常已解决(代码片段