MyBatis报错:org.apache.ibatis.binding.BindingException: Type interface com.smbms.dao.provider.Provider
2019-08-15 19:35
1391 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43199016/article/details/99652033
在Java使用MyBatis框架开发时,遇到报错:
org.apache.ibatis.binding.BindingException: Type interface com.smbms.dao.provider.ProviderMapper is not known to the MapperRegistry.的解决方案。
首先我们分析这个错误,这个错误报的是没有绑定映射文件
binding.BindingException,所以这个错误只要在MyBatis中加上对应的配置文件即可。
org.apache.ibatis.binding.BindingException: Type interface com.smbms.dao.provider.ProviderMapper is not known to the MapperRegistry. at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:47) at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:779) at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:291) at com.smbms.test.TestProviderMapper.testGetProviderCount(TestProviderMapper.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:389) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:1
解决方案(在mybatis-config.xml中加入映射文件):
未加入所需配置文件时的mybatis-config.xml中的mappers节点
<!--配置SQL映射文件--> <mappers> <mapper resource="com/smbms/dao/user/UserMapper.xml"/> </mappers>
加入所需配置文件时的mybatis-config.xml中的mappers节点
<!--配置SQL映射文件--> <mappers> <mapper resource="com/smbms/dao/user/UserMapper.xml"/> <!--添加为映射的文件--> <mapper resource="com/smbms/dao/user/ProviderMapper.xml"/> </mappers>
出现这种错误的第二种类型:
org.apache.ibatis.binding.BindingException: Type interface com.hx.dao.provider.ProviderMapper is not known to the MapperRegistry. at org.apache.ibatis.binding.MapperRegistry.getMapper(MapperRegistry.java:42) at org.apache.ibatis.session.Configuration.getMapper(Configuration.java:639) at org.apache.ibatis.session.defaults.DefaultSqlSession.getMapper(DefaultSqlSession.java:218) at com.hx.dao.provider.ProviderMapperTest.testGetProviderList(ProviderMapperTest.java:46) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
注意报错中提示的:
is not known to the MapperRegistry.这个表示没有这个映射地址,也就是说虽然配置文件中配置了,又能是SQL配置文件Mapper.xml中配置错误了,也有可能
namespace中编写时出了错误,看下面一个实例:
- namespace的设置与文件实际的位置不同
将上面的namespace修改为正确位置后问题就解决了,如果不是这里出错那么久可能是xml中的mappers节点配置错误啦。
完成后这个问题就解决了,如果以上步骤完成后运行时还报错那么说明,那么xml配置文件错误了,查找方向为优先SQL映射文件(Mapper结尾的文件),然后再看mybatis-config.xml的错误,不过虽然MyBatis框架一般都是xml配置文件的编写错误,还是需要注意自己的Java代码是否有写正确!
相关文章推荐
- 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add
- org.apache.ibatis.binding.BindingException: Type interface dxm.com.mapper.UserMapper is not known to
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.msg.dao.UserRec
- org.apache.ibatis.binding.BindingException: Mapper method 'com.zbiti.alarm.dao.AlarmDao.queryTest at
- Exception in thread "main" org.apache.ibatis.binding.BindingException: Mapper method 'com.demo.DAO.B
- org.apache.ibatis.binding.BindingException: Mapper method 'com... has an unsupported return type
- 解决org.apache.ibatis.binding.BindingException: Type interface xxx is not known to the MapperRegistry
- 解决org.apache.ibatis.binding.BindingException: Type interface xxx is not known to the MapperRegistry
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yj.dao.TrailerA
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.demo.dao.UserDa
- mybatis报错整理:org.apache.ibatis.binding.BindingException
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题
- mybatis:方法需要传入多个参数时,报错:Caused by: org.apache.ibatis.binding.BindingException: Parameter 'p_v_id' not
- FAQ(10):Type interface com.smbms.dao.UserMapper is not known to the MapperRegistry.
- Spring错误:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Bi
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingExce
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
- mybatis多参数查询问题:org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available par
- maven项目中mybatis的Mapper文件没有编译,导致错误org.apache.ibatis.binding.BindingException: Invalid bound statement
- mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)”