在学习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

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐