在学习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相对路径保持一致。



