栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

MyBatis使用getMapper时出现org.apache.ibatis.binding.BindingException

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MyBatis使用getMapper时出现org.apache.ibatis.binding.BindingException

问题

在学习MyBatis使用动态代理的方式进行测试时遇到 org.apache.ibatis.binding.BindingException: Type interface org.example.dao.StudentDao is not known to the MapperRegistry. 如下图所示

原因

MyBatisUtils.getsqlSession().getMapper(StudentDao.class) 该代码是首先创建SqlSession对象,然后调用SqlSession对象的getMapper()方法去动态获取StudentDao.xml中StudentDao的命名空间namespace(使用全限定名称,即StudentDao接口的相对路径),获取到namespace后赋值给StudentDao对象studentDao,然后studentDao再调用StudentDao中具体的方斜体样式法。如果StudentDao.xml中namespcae写的路径与StudentDao接口不一致,则会在运行时找不到其对应的方法,所以namespace一定要与StudentDao相对路径保持一致。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/720597.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号