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

报错问题: 未找到数据库url等配置信息。Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

错误日志:

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

背景:

通过dockerfile打包部署后,在启动时提示,配置数据源失败:未指定“url”属性,无法配置嵌入式数据源Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

排查过程:

​ 在看到 'url' attribute is not specified and no embedded datasource could be configured.未指定“url”属性,无法配置嵌入式数据源后,首先确认编译后的target包或生成的jar包的./classes/目录下是否存在application.ymlapplication.properties配置文件,经确认发现编译后的jar包内并没有此配置文件,那么问题原因就找到了,真相只有一个,就是Maven在编译的过程中没有将普通配置文件编译进jar包内。

报错原因:

​ 我们知道Maven是根据pom.xml执行任务,其中build标签描述了如何来编译及打包项目,而具体的编译和打包工作是通过build中配置的 plugin 来完成。而对于**resources目录下资源,往往不是代码(.propertiesXML配置文件),无需编译,所以在构建过程中往往会将资源文件从源路径直接复制到指定的目标路径。**

src/main/javasrc/test/java这两个目录中的所有*.java文件会分别在comiletest-comiple阶段被编译,编译结果分别放到了target/classestarge/test-classes目录中,但是这两个目录中的其他文件都会被忽略掉。

解决办法:

需要在你的项目的pom文件中添加一下配置

<build>
	<resources>
        <!-- 解决mapper绑定异常 -->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.yml</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <!-- 解决未找到数据源等配置文件异常 -->
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.yml</include>
            </includes>
        </resource>
    </resources>
</build>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值