APPLICATION FAILED TO START Failed to configure a DataSource: ‘url‘ attribute is not specified and

文章描述了在遇到APPLICATIONFAILEDSTART错误,无法配置DataSource时的问题。原因是缺少对application.yml中定义的数据库连接信息的读取。解决方案在于更新pom.xml文件,添加资源配置,确保能识别.yml文件,特别是对于使用MySQL数据库的情况,需注意驱动类和URL的正确设置。
摘要由CSDN通过智能技术生成

***************************

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

最近报了一个这样的错误,意思是没有提供数据库连接

可是我明明在application.yml配置文件中写了数据库的连接

server:

  port: 8080

spring:

  datasource:

    driver-class-name: com.mysql.jdbc.Driver

    url: jdbc:mysql://localhost:3306/mydatabase?characterEncoding=utf8

    username: root

    password: 123

注意:如果你的数据库是8.0版本及以上的需要更改驱动和url

    driver-class-name: com.mysql.cj.jdbc.Driver

    url: jdbc:mysql://localhost:3306/mydatabase?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false

找了很久原来是pom.xml文件中没有写让他去找application.yml文件

所以需要在pom.xml文件的build标签中添加

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

注意:如果你的配置文件是以.properties文件名结尾的,需要将上述代码中的.yml更改成.properties

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值