Java-Springboot启动报错Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedde

前言

SpringBoot项目启动报错:

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured
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)

分析

按照报错信息所示,直接原因是加载不到数据源的url信息,提示我们需要将数据源等配置放置在加载路径中。
这也就说明了问题点,即没有加载到配置文件application.properties或者application.yaml

在这里插入图片描述
打开我们的target目录可以看到,确实没有加载到相应的配置文件。

解决方法

1、确保配置文件的位置

对于常规Spring Boot应用,配置文件应位于src/main/resources目录下

2、Maven资源过滤问题

确保Maven在打包时正确地处理了资源文件。在pom.xml中的标签内添加或确认已存在如下配置:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>**/*.properties</include>
            <include>**/*.yml</include>
        </includes>
    </resource>
</resources>

告诉Maven将指定的资源文件从src/main/resources目录复制到最终的打包文件中

3、使用maven命令或者手动删除target,重新编译打包

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

只吹45°风

一切随心,感激您的每一份支持。

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

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

打赏作者

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

抵扣说明:

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

余额充值