Spring-Mybatis整合


问题描述:

提示:在进行mybatis与Spring的整合过程中抛出了以下异常信息:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user '洪学添'@'localhost' (using password: YES))
### The error may exist in com/ssm/mapper/UserMapper.xml
### The error may involve com.ssm.mapper.UserMapper.findUserById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user '洪学添'@'localhost' (using password: YES))

原因分析:

捕获到关键信息点:Failed to obtain JDBC Connection,意指JDBC连接失败,可能出现这个错误的地方,properties文件书写有误,需要先检查;如果仔细检查后没有问题,则继续检查是否发生命名冲突的问题。


解决方案:

对于原因2可以采取如下方法解决:
将原数据库配置文件properties
在这里插入图片描述
修改成:
在这里插入图片描述

最后在spring的配置文件中进行相应的更改即可。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐