`
东天里的冬天
  • 浏览: 32756 次
  • 性别: Icon_minigender_1
文章分类
社区版块
存档分类
最新评论

解决:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

 
阅读更多

之前有用过SSM框架,并且自己搭过,完全没问题。工作之后一直用maven,前两天在maven下搭建了一个SSM框架,但是一直报绑定失效错误,具体错误如下:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey
    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.$Proxy57.selectByPrimaryKey(Unknown Source)
    at com.pet.service.Imp.PetServiceImp.getPetById(PetServiceImp.java:27)
    at com.pet.controller.Controller.dologin(Controller.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2536)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2525)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

一般碰到这种错误有两种原因:

一.*Mapper.java文件与*Mapper.xml文件对应信息不一致,解决方案如下:

1:检查两个文件是否在同一个包中(如果有指定xml文件,则不需要考虑这点)

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

3:检查函数名称与xml文件中的id能否对应上

4:检查函数的参数类型以及返回类型与xml文件能否对应上

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

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


二.用maven或者IDEA中自动扫描了resources目录下的文件,无法扫描*Mapper.xml文件,同时无法将配置文件加载到classes目录下解决方案:

在pom.xml中加入如下配置:

 <build>
    <resources>  
      <!-- maven项目中src源代码下的xml等资源文件编译进classes文件夹,
      	注意:如果没有这个,它会自动搜索resources下是否有mapper.xml文件,
      	如果没有就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey-->
      <resource>  
        <directory>src/main/java</directory>  
        <includes>  
          <include>**/*.xml</include>  
        </includes>  
      </resource>
      
      <!--将resources目录下的配置文件编译进classes文件  -->  
      <resource>
			<directory>src/main/resources</directory>
	  </resource>
    </resources>  
  </build> 



分享到:
评论

相关推荐

    解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found

    出现以上的情况主要的原因是因为在主配置文件标签没...解决方案:1.检查的name是否正确,如我的name属性填的就是com.it.dao 2、检查的class属性或resource属性,我resource这里写的是name="com/it/dao/iAccountDao.xml"

    Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法

    在使用Mybatis框架时,你可能会遇到`org.apache.ibatis.exceptions.PersistenceException`这样的异常。这个异常通常表示在执行数据库查询操作时遇到了问题。本篇将详细分析这个问题并提供解决方法。 ### 问题概述 ...

    mybatisplus报Invalid bound statement (not found)错误的解决方法

    在使用MyBatisPlus进行开发时,可能会遇到一个常见的错误——`Invalid bound statement (not found)`。这个错误通常表示MyBatisPlus无法找到你尝试调用的Mapper接口的方法。本文将详细解析这个问题的原因以及提供...

    ibatis-core-3.0.jar org.apache.ibatis.annotations.Param

    `org.apache.ibatis.annotations.Param`是MyBatis中的一个重要注解,用于处理方法参数映射。 `@Param`注解主要用于SQL查询中的动态参数绑定,尤其是在动态SQL语句中。在MyBatis的映射文件或者Mapper接口中,当我们...

    Caused by: java.net.UnknownHostException: openapi.alipay.com

    Caused by: java.net.UnknownHostException: openapi.alipay.com

    mybaits refid patch

    Caused By: org.apache.ibatis.builder.BuilderException: Could not find SQL statement to include with refid 'SAD02.SAD02_COL' at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler....

    spring-framework-3.0.5.RELEASE-dependencies-5

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-1

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-6

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-3

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-2

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-8

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-4

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    spring-framework-3.0.5.RELEASE-dependencies-7

    org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache.xmlcommons org.apache.derby org.apache.poi org.apache....

    使用的ognl的chm

    **OGNL(Object-Graph Navigation Language)**是一种强大的表达式语言,主要用于获取和设置Java对象的属性。在Java开发中,尤其是Web应用框架如Struts2和Hibernate中,OGNL被广泛使用。它允许开发者以简洁的方式...

    Basic编译快手

    通过不断的实践,可以逐步提升编程思维和问题解决能力。 总的来说,Basic编译快手是初学者接触编程、学习Basic语言的理想工具,它的易用性和实用性有助于快速掌握编程基础,为进一步深入学习其他编程语言打下坚实的...

    mybatis源码中文注释.zip

    org.apache.ibatis.logging org.apache.ibatis.logging.commons org.apache.ibatis.logging.jdbc org.apache.ibatis.logging.jdk14 org.apache.ibatis.logging.log4j org.apache.ibatis.logging.log4j2 org.apache....

    前端-后端java的Util类的工具类

    │ │ │ frame-sourcefiles-org.apache.ibatis.binding.html │ │ │ frame-sourcefiles-org.apache.ibatis.builder.annotation.html │ │ │ frame-sourcefiles-org.apache.ibatis.builder.html │ │ │ frame-...

    ibatis-2.3.4.726.jar,ibatis-2.3.0.677.jar,ibatis-2.3.3.720.jar下载

    iBATIS,全称为“Infrastructure for Binding Applications To SQL Maps”,是一个优秀的开源持久层框架,它允许Java开发者将SQL语句与Java代码分离,提供了一种简单但强大的在Java应用中映射SQL和结果集的方式。...

Global site tag (gtag.js) - Google Analytics