spring和mybatis整合时Access denied for user '***'@'localhost' (using password: YES)错误的解决方案

参考文章:博客园文章

参考解决办法:

将数据库配置文件格式

key=value

改为

jdbc.key=value

以下为问题分析

使用Spring + Mybatis + Mysql整合时,测试报错

SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d296da] was not registered for synchronization because synchronization is not active

Access denied for user '***'@'localhost' (using password: YES)

整合时运行是没有问题的,然后我修改为使用外部prop配置文件后,通过Spring配置文件导入数据库配置信息,报的这个错误.再结合错误提示,猜测是由于用户名或密码错误导致,网上查找发现是因为prop文件key名称写错
如下:
jdbc.properties文件内容(错误的)

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
username=root
password=test

key前面加上jdbc.key即可解决
修改后

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
jdbc.username=root
jdbc.password=test

再次运行成功!

posted @ 2020-09-10 18:02  juyss  阅读(795)  评论(0编辑  收藏  举报