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).
大家好,我在开发一个 Spring Boot 项目,使用 MyBatis 连接 MySQL 数据库时遇到了问题,希望得到各位的帮助。
项目使用 Maven 构建,pom.xml 中引入了以下依赖:
然后在 application.yml 中配置了数据源:
spring: datasource: url: jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver
mybatis: mapper-locations: classpath:mapper/Mapper.xml type-aliases-package: com.example.demo.entity
但是当我启动项目时,出现了如下异常:
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).
我检查了数据库连接 URL、用户名、密码,都没有问题。数据库 mydb 也确实存在。但就是连接不上。
我看了一些博客,有的说要在 MySQL 命令行客户端中执行 create database mydb; 命令,我试了一下,还是不行。
请问各位有遇到过类似问题吗?我应该如何修改配置才能让 Spring Boot 项目成功连接到 MySQL 数据库?