zoukankan      html  css  js  c++  java
  • Mybatis异常_03_Invalid bound statement (not found)

    一、异常信息

    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)

  • 相关阅读:
    手速太慢QAQ
    最短路总结
    放下
    素材收集
    NOI2018旅游记
    -5
    七月
    德国GG了
    本人自传
    bzoj2369
  • 原文地址:https://www.cnblogs.com/shirui/p/8268930.html
Copyright © 2011-2022 走看看