若在运行SpringBoot项目时,出现如下错误:
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).
Disconnected from the target VM, address: '127.0.0.1:31456', transport: 'socket'
出现该错误的原因是:没有连接数据库,需要在application.properties(下图)中添加配置数据库的代码:
配置数据库的代码为:
# 数据库的配置信息
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/myblog?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
文章来源:https://www.toymoban.com/news/detail-539351.html
添加完毕后,即可成功运行。文章来源地址https://www.toymoban.com/news/detail-539351.html
到了这里,关于SpringBoot项目出现Failed to configure a DataSource错误时解决方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!