若在运行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
添加完毕后,即可成功运行。