SpringBoot项目启动报错Failed to configure a DataSource

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

注意:本文只适用于已经配置了数据库的项目,但是仍然报这个错误。

解决方法:①pom.xml依赖不要忘了加

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version><!--最好选一个版本,不然有的项目maven会报错--></version>
    <scope>runtime</scope>
</dependency>

②项目配置文件(例如application.yml)里面数据源配置写法是否正确

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
    username: root
    password: 123456

猜你喜欢

转载自blog.csdn.net/qq_70143756/article/details/129830188
今日推荐