MySQL版本5.7,连接本地数据库时出错

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

当时在yml配置文件里是这样的:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true
经过导师和同事debug,才知道是username和password没加。自己debug的时候,是有好几个yml配置文件的,application.yml是有username和password的,application-prd_cn.yml、application-preprd_cn.yml、application-stg_cn.yml都是没有username和password。我以为一处配置,其他都会生效,然而并没有…改成下面这样就没有报错了。
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: sqsq1212
url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=UTC&useSSL=false&allowPublicKeyRetrieval=true

你可能感兴趣的:(MySQL,数据库,mysql,java)