Could not find resource

问题描述:mybatis找不到mapper
Could not find resource

问题分析:在mybatis配置文件中用的resource,但是写成了dao.BookMapper,应该写mapper.xml文件的全限定路径。

Could not find resource

解决方法:
Could not find resource
mybatis中的mapper使用方法:

<!-- 使用相对于类路径的资源引用 -->
<mappers>
  <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
  <mapper resource="org/mybatis/builder/BlogMapper.xml"/>
  <mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>
<!-- 使用完全限定资源定位符(URL) -->
<mappers>
  <mapper url="file:///var/mappers/AuthorMapper.xml"/>
  <mapper url="file:///var/mappers/BlogMapper.xml"/>
  <mapper url="file:///var/mappers/PostMapper.xml"/>
</mappers>
<!-- 使用映射器接口实现类的完全限定类名 -->
<mappers>
  <mapper class="org.mybatis.builder.AuthorMapper"/>
  <mapper class="org.mybatis.builder.BlogMapper"/>
  <mapper class="org.mybatis.builder.PostMapper"/>
</mappers>
<!-- 将包内的映射器接口实现全部注册为映射器 -->
<mappers>
  <package name="org.mybatis.builder"/>
</mappers>

总之:在spring中,如果是限定文件的位置用 /
如果是限定接口或类的位置用 .

上一篇:Could not autowire. No beans of 'xxx' type found


下一篇:关于rundll32