Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)

一、问题详情

IDEA2019中在搭建Mybatis简化DAO操作时报错:

错误分析:初步判断存在于配置文件UserMapper.xml中。

错误详情:

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in cn/library/mapper/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource cn/library/mapper/UserMapper.xml

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)


二、问题解决

首先检查UserMapper.xml,查看是否是中英文错误,是否是SQL语句错误,发现UserMapper.xml文件中并没有错误

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)

然后,检查sqlMapConfig.xml文件中的加载映射文件是否出现问题:

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)

配置同按照resources资源文件下的格式配置,应该没有问题,但是!!!

问题就是出现在这!

通过右击UserMapper.xml文件,选择copy path

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)

sqlMapConfig.xml文件中粘贴路径发现问题,原路径有问题:

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)

将其注释重新运行,运行成功!

Error building SqlSession.The error may exist in cn/library/mapper/UserMapper.xml(Mybatis搭建测试中的错误解决)


 

       欢迎关注博主,欢迎互粉,一起学习!

       感谢您的阅读,不足之处欢迎指正!