SpringBoot project startup error 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

Note: This article is only applicable to projects that have configured a database, but this error is still reported.

Solution: ①Do not forget to add pom.xml dependencies

<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version> <!--It is best to choose a version, otherwise some projects maven will report an error--> </version> 
    <scope>runtime</scope> 
</dependency>

② Whether the data source configuration in the project configuration file (such as application.yml) is written correctly

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

Guess you like

Origin blog.csdn.net/qq_70143756/article/details/129830188