Mybatis异常_03_Invalid bound statement (not found)

简介: 一、异常信息 Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.

一、异常信息

Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.hand.hec.nghec.sys.mapper.SysServiceMapper.selectService
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:196)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:44)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy169.selectService(Unknown Source)
    at com.hand.hec.nghec.sys.service.impl.SysServiceServiceImpl.select(SysServiceServiceImpl.java:26)
    at com.hand.hec.nghec.sys.service.impl.SysServiceServiceImpl.select(SysServiceServiceImpl.java:1)
    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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at com.hand.hap.core.impl.ServiceExecutionAdvice.invoke(ServiceExecutionAdvice.java:169)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy170.select(Unknown Source)
    at com.hand.hap.system.controllers.BaseController.query(BaseController.java:68)

 

 

二、异常原因

一般的原因是Mapper interface和xml文件的定义对应不上,

需要检查包名,namespace,函数名称等能否对应上,

需要比较细致的对比,我经常就是写错了一两个字母搞的很长时间找不到错误

 

三、异常解决过程

1.常见解决方法

出现这个错误时,按以下步骤检查一般就会解决问题:

 

1:检查xml文件所在的package名称是否和interface对应的package名称一一对应

2:检查xml文件的namespace是否和xml文件的package名称一一对应

3:检查函数名称能否对应上

4:去掉xml文件中的中文注释

5:随意在xml文件中加一个空格或者空行然后保存

 

一般来说到此就可以排除错误了

 2.我的原因与解决方法

(1)原因

原因还是因为Mapper interface和xml文件的定义对应不上

这是因为我一个web工程依赖了两个jar工程,而这两个jar工程 mapper.xml文件的目录结构相似,并且映射路径也相同,这导致mybatis只扫描了其中一个jar工程的xml,而不扫描另一个的。

 

applicationContext.xml

 

jar工程1目录:

 

 jar工程2目录:

 

 (2)解决方法

 修改applicationContext.xml 中 mapper文件映射路径:

 

 写成两个就可以了

 

(3)存疑

如上述配置文件中,mybatis  一个 value  只扫一个工程的。 所以要为每个工程单独配置一个value.

 

 

四、参考资料

1.mybatis绑定错误-- Invalid bound statement (not found)

 

目录
相关文章
|
7月前
|
XML Java 数据库连接
解决在mybatis中使用class属性绑定映射文件出现的异常问题~
解决在mybatis中使用class属性绑定映射文件出现的异常问题~
|
7月前
|
关系型数据库 Java Go
解决 MyBatis-Plus + PostgreSQL 中的 org.postgresql.util.PSQLException 异常
解决 MyBatis-Plus + PostgreSQL 中的 org.postgresql.util.PSQLException 异常
412 0
|
22天前
|
Java 关系型数据库 MySQL
整合SpringBoot与MyBatis时报错时区异常
整合SpringBoot与MyBatis时报错时区异常
15 0
|
7月前
|
SQL Java 数据库
【Mybatis-plus异常】mybatis-plus updateById方法更新不了空字符串和null的解决方法
【Mybatis-plus异常】mybatis-plus updateById方法更新不了空字符串和null的解决方法
158 0
|
5月前
|
SQL IDE Java
MyBatis【问题 01】mapper传入array\collection\list类型的参数时报BindingException:Parameter ‘xx‘ not found问题复现及解决
MyBatis【问题 01】mapper传入array\collection\list类型的参数时报BindingException:Parameter ‘xx‘ not found问题复现及解决
60 0
|
10月前
|
存储 SQL 缓存
【问题处理】—— Mybatis缓存可改导致的异常
【问题处理】—— Mybatis缓存可改导致的异常
93 0
|
7月前
|
Java 数据库连接 mybatis
【Mybatis异常】nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter
【Mybatis异常】nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter
179 0
|
11月前
|
SQL 数据库
springboot+mybatis,mapper调用查询的数据为空,报空指针异常
springboot+mybatis,mapper调用查询的数据为空,报空指针异常
734 0
|
2月前
|
SQL Java 数据库连接
挺详细的spring+springmvc+mybatis配置整合|含源代码
挺详细的spring+springmvc+mybatis配置整合|含源代码
46 1
|
2天前
|
SQL Java 数据库连接
15:MyBatis对象关系与映射结构-Java Spring
15:MyBatis对象关系与映射结构-Java Spring
15 4