【踩坑专栏】Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

在启动demo的时候,遇到了如题的问题,完整信息如下

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

看起来是说没有配置数据源。但是application.yml已配置,数据源及对应依赖也已添加,经过一番查证,发现是yml没有被编译进来。
在这里插入图片描述

就算在pom里指定路径[2],也没有用。其实按道理来说。idea会自动将resources这个derictory中的配置文件编译,不需要额外指定的。

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>

最后在这篇文章[1]中找到了答案,方法简单有效:直接将appliation.yml复制进target中进行编译。
点击yml,Ctrl+C复制。再点击classes,Ctrl+V即可。
在这里插入图片描述

再次启动,成功
在这里插入图片描述

目前尚不清楚问题的原因,文章[1]中作者说可能是idea的问题.
我建了一个空的git远程仓库,空仓库clone下来后,新建java、resource目录,并从出问题的项目那复制yml等文件过来,target目录中依然没有yml,却可以成功启动。自己在本地直接new了一个project,也是这个问题。

后来查证了一下,发现不是idea的问题,是pom文件中指定的打包方式的问题,应该取消掉pom类型的打包方式[3],或者改为jar方式打包<packaging>jar</packaging>都可以
在这里插入图片描述

参考文章:
[1],解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource coul
[2],target没有xml、yml的编译文件
[3],idea springboot应用报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值