Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured两种解决办法。
在学习springboot中,项目启动报Failed to configure a DataSource错误
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 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或者application.yml文件配置文件:
#设置数据库连接配置
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/XXXX?serverTimezone=Asia/Shanghai
spring.datasource.username=xxx
spring.datasource.password=xxxxxx
问题二: target 文件夹下yml或者properties文件没有被扫描到:
需要在pom.xml文件中添加如下.来保证文件都能正常被扫描到并且加载成功。
<!--手动指定文件夹为resources-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**.*.yml</include>
<include>**.*.yaml</include>
</includes>
</resource>
</resources>