Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could

7 篇文章 0 订阅

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).

在做多模块任务启动时,遇到了这个错误

错因有三:

1、检查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

2、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>

3、配置文件出现配置覆盖

这也是我报错的原因!!!!

因为我再没有分模块写代码的时候顺手将springboot启动模块的配置文件改成了yml文件,以至于加载配置文件的时候读取了空白的配置文件,导致数据库连接不上!

 可能是由于我mapper层模块的配置文件也是yml文件,所以就没有读取我的文件配置

所以只需要将springboot启动模块的配置文件重写改成properties文件就可以了!

 注:

两者的加载顺序

    正常的情况是先加载yml,接下来加载properties文件。如果相同的配置存在于两个文件中。最后会使用properties中的配置。最后读取的优先集最高。

   两个配置文件中的端口号不一样会读取properties中的端口号

如果本篇文章对你有帮助,还请一键三连【开心】

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YOUNG.K

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值