在学习MyBatis时候,在sqlMapConfig.xml中导入xxxMapper.xml,却发现死活找不到xxxMapper.xml。特此记录下解决方法。
运行项目发生以下报错提示Could not find resource com/jundeng/mapper/UserMapper.xml
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com.samarua.mapper.UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/jundeng/mapper/UserMapper.xml
再看目录结构,UserMapper.xml明明是存在的。
解决办法1:
把sqlMapConfig.xml
中的引用路径的.
改为/
<mappers>
<!--com.jundeng.mapper.UserMapper.xml-->
<mapper resource="com/jundeng/mapper/UserMapper.xml"></mapper>
</mappers>
解决办法2:
当替换后还无法解决问题的,则是maven目录结构产生了错误,此时需要删除原有目录并重新创建,在创建多级目录时,目录名也应使用com/jundeng/mapper
而不是com.jundeng.mapper