Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
原文链接:Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured. – 每天进步一点点 (longkui.site)
某日新创建一个spring boot项目,添加完依赖以后运行项目开始报错:
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).
原因1:没有配置文件
这个报错主要是因为数据库没有配置,比如一开始这个项目,添加完mysql依赖后直接启动项目导致没有读取到mysql的相关配置,这个时候可以先注释掉mysql的依赖,然后刷新maven依赖重新启动项目。
如果配置了相关的文件或者想要使用配置文件,可以继续往下看。
原因2:配置不正确
如果确实加入了mysql的相关配置,大概率是配置的格式不正确,比如下面这样:
一共两个错误,一是spring前面有空格,它的层级和上面的port一级了。
二是url后面的配置没有空格,可以看出url这个没有正常变色
(这种写法很像python!)
修改错误后,改成下面这样:
重新启动项目后就正常了。
如果报下面的错请参考
Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver’.