Maven中使用MyBatis框架报如下错误:
MySQL 8.0.19
JDK 1.8
Maven 3.6.3
在这里插入代码片org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.Driver
### The error may exist in com/itcode/dao/Mapper.xml
### The error may involve com.itcode.dao.UserMapper.selectById
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.Driver
**上述问题是因为无法读取到数据库驱动 **
解决方案
-
要确保Maven工程成功导入数据库连接的依赖
-
确保主配置文件数据库的连接配置无误
-
如果1、2都确保无误再看第三条吧!
我是这样粗暴导入的~
哪个小可爱有别的更优方案,踢我以下!!!