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

一、问题描述

启动Springboot项目后启动报错,本人第一种方法解决

无法配置DataSource:未指定'url'属性,也无法配置嵌入数据源。

很明显,就是在应用中没有配置datasource的一些相关属性,例如:数据库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).

说明:

未能配置DataSource:未指定“url”特性,也无法配置任何嵌入的数据源。

原因:无法确定合适的驱动程序类别

操作:

考虑以下内容:

如果您想要一个嵌入式数据库(H2、HSQL或Derby),请将其放在类路径中。

如果您有要从特定配置文件加载的数据库设置,则可能需要激活它(当前没有激活的配置文件)。

二、方法1

        yml或者properties文件没有被扫描到,在pom文件中添加如下,来保证文件都能正常被扫描到并且加载成功

<build>
        <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>
    </build>

三、方法2

排除此类的autoconfig。启动以后就可以正常运行。

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})

四、方法3

检查application.yml文件中数据库配置信息

spring:
  #数据源配置
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/dmw?createDatabaseIfNotExist=true&autoReconnect=true&default-character-set=utf8&&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver

有用请点赞,养成良好习惯!

疑问、交流、鼓励请留言!

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

慕白Lee

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

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

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

打赏作者

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

抵扣说明:

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

余额充值