Spring整合Mybatis过程中遇到的一个奇怪问题.md

我安装的mysql版本为8.0.14,项目中使用的mysql-connector版本为5.1.6,启动mybatis-generator插件,错误如下:

Client does not support authentication protocol requested by server; consider upgrading MySQL client

研究了一下,发现是mysql-connector版本过低导致的,于是更新至8.0.11。重启运行mybatis-generator插件,成功根据数据库表结构生成实体类和基本查询。说明此事我的项目是可以成功连接数据库的。
配置tomcat,项目可以启动。通过浏览器发送请求测试,返回错误如下:

Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Client does not support authentication protocol requested by server; consider upgrading MySQL client)

因为括号中的这句话,我误以为是mybatis的版本过低导致的,所以将其从3.4.1改为3.5.0,结果导致项目无法启动,错误如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mapperScannerConfigurer' defined in class path resource [applicationContext-datasource.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSession

看似是缺少jar包造成的,但搜索一圈后发现可能是由于调整后mybatis版本与spring有冲突,所以将mybatis改回3.4.1,项目又可以启动了,一切又回到了解放前。
反复研究Client does not support authentication protocol requested by server; consider upgrading MySQL client. 这个提示,发现很多解决方案都指向修改mysql的密码。这时root的密码为123,使用命令行、Navicat、以及上文的generator插件均能成功连接,所以一直没有尝试过修改密码这个方案。无奈尝试将数据库密码修改为123456,并修改项目配置,居然成功了。修改密码命令如下:

ALTER USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY '123456';

不明觉厉。

猜你喜欢

转载自blog.csdn.net/weixin_41657493/article/details/87213279