Invalid bound statement (not found)错误的可能原因

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Invalid bound statement (not found)错误的可能原因相关的知识,希望对你有一定的参考价值。

参考技术A

Invalid bound statement (not found)这个问题的实质就是 mapper接口和mapper.xml没有映射起来

常见的低智商问题有下列几个:

1.mapper.xml 里面的 namespace与实际类不一样
mapper.xml 里面的 namespace应该是其对应的接口路径。这个有个快捷的检测办法就是按住ctrl键,然后点击namespace里面的包名,如果能跳到对应的类,那就说明没问题。

2.mapper接口的函数名称和mapper.xml里面的标签id不一致
这个问题也很常见,最好的办法还是复制过去,这样可以确保没得问题,1点和2点都是关于拼写错误的情况

3.构建没有进去,请看一下target文件夹下面这些是否存在,没有请重新构建

4.包扫描路径是否正确
检查mybatis的配置是否正确,需要配mapperLocations和typeAliasesPackage属性。
也可以在springboot启动类上面加@MapperScan注解,指定扫描路径

5.配置文件写错
如果你是Mybatis的话请注意yml或者properties文件里面的

如果你是Mybatis plus 这个时候你要注意了,mybatis plus是下面这样的配置,如果你发现1,2,3,4点的问题都没有问题,你需要注意一下这个东西

Mybatis 异常记录: Invalid bound statement (not found)

 

错误信息:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pingan.credit.dao.mapper.TdReportMapper.insertQueryLog

    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:223)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy44.insertQueryLog(Unknown Source)
    at com.pingan.credit.TestService.TestTdCase.testQueryLog(TestTdCase.java:1014)
    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:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

 

一般是Mapepr.xml文件中文nameapce没有和mapper接口发生映射,导致mybatis绑定失败

检查namespace 绑定mapper.java的 路径是否正确

以上是关于Invalid bound statement (not found)错误的可能原因的主要内容,如果未能解决你的问题,请参考以下文章

Invalid bound statement not found

Invalid bound statement (not found) 错误原因

报错 Invalid bound statement (not found): com.xxx.mapper.xxx

Invalid bound statement (not found)

Mybatis 异常记录: Invalid bound statement (not found)

mybatis错误:Invalid bound statement (not found)