解决Maven项目中 Invalid bound statement 无效的绑定问题

问题

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

关于这个问题,我的是 Maven 项目,在访问程序的接口时,抛出异常信息,无效的绑定语句。

在检查调用的 Mapper 接口时,发现在目标文件中没有找到 Mapper 映射的配置文件,在项目的 target 目标文件中可以看到,与接口对应的 Mapper 文件未加载,所以在程序启动时,就找不到对应的映射文件,导致的这个错误。

解决方法

在 pom 配置文件中键入<build> 节点,并指明资源类型,这样在程序启动时,就可以正确加载配置文件了:

Java中的配置资源类型:

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

Resource中的配置资源类型:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

当然项目需求可以同时键入两个:

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

键入<build> 节点后,在次启动项目,在项目的 target 目标文件中,就可以看到接口对应的映射文件了,问题解决咯!!!!

开发maven时遇到无效的绑定语句(未找到),org.apache.ibatis.binding.BindingException:

今天做一个springmvc+mybatis的maven项目时运行登录时报错,显示找不到绑定语句

日志文件如下

严重 [http-nio-8080-exec-9] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [crm] in context with path [/boot_crm_war] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.itheima.core.dao.UserDao.findUser] with root cause
 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.itheima.core.dao.UserDao.findUser
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:230)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
	at com.sun.proxy.$Proxy15.findUser(Unknown Source)
	at com.itheima.core.service.impl.UserServiceImpl.findUser(UserServiceImpl.java:20)
	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 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.$Proxy19.findUser(Unknown Source)
	at com.itheima.core.web.controller.UserController.login(UserController.java:25)
	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.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

我按照网上的方法怎么看都没发现自己有错误,很烦恼。但是他说找不到绑定语句,我明明绑定语句没有错误,为什么找不到呢?于是我去target文件夹看看我的classes有没有编译出来,看了之后一目了然。

我们的class文件被编译了,但是绑定语句xml文件没有被编译。

在做maven项目时,以后都要注意一个点,要在build标签里加上这个语句

<resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.xml</include>
      </includes>
      <filtering>true</filtering>
    </resource>
  </resources>

xml文件才能够被编译。加入之后重新编译,文件夹就多了xml文件。

问题解决。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • MyBatis绑定错误提示BindingException:Invalid bound statement (not found)的解决方法

    如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上. 按以下步骤一一执行: 1.检查xml文件所在的package名称是否和interface对应的package名称一一对应 2.检查xml文件的namespace是否和xml文件的package名称一

  • Maven配置多仓库无效的解决

    在项目中使用Maven管理jar包依赖,往往会出现以下状况: 1.国内访问maven默认远程中央镜像特别慢: 2.使用阿里的镜像替代远程中央镜像: 3.阿里云镜像中缺少部分jar包: 4.同时使用私有仓库和公有仓库: 针对以上情况,我们就需要让Maven支持多仓库配置. 单独仓库配置 当只配置一个仓库时,操作比较简单,直接在Maven的settings.xml文件中进行全局配置即可,以阿里云的镜像为例: <mirrors> <mirror> <id>alimaven&l

  • idea2019导入maven项目中的某些问题及解决方法

    idea2019导入maven项目中的某些问题 idea2019导入maven项目,会出现很多莫名其妙的问题,需要注意的是如果是idea2019的版本是3月以前的,那会maven需要下载3.6.1以前版本,3.6.2版本不兼容 需要3.6.1版本的童鞋可在官网下载,或者用下面链接获取: 链接: https://pan.baidu.com/s/1nkJNF1OUuzHxgsBHXa5gow 提取码: snk3 配置maven的setting.xml文件 如果导入依赖出现问题时,可从以下几方面查看:

  • 引入mybatis-plus报 Invalid bound statement错误问题的解决方法

    错误 Mybatis-Plus (简称MP) 是mybatis的一个增强工具,在mybatis的基础上只做增强不做改变,简化了开发效率.其实就是帮我们封装了一些简单的curd方法,可以直接调用,不必再重写这些简单的sql语句,类似JPA那样. 前两天创建了一个新项目,持久层框架用的是mybatis,同时引入mybatis-plus做增强工具,项目启动后,调用接口却发现报错了,报错的提醒如下: 错误的信息显示的是 "无效的绑定语句",报错的地方正是操作sql语句的方法,从网上查了一下答案

  • 解决Maven项目中 Invalid bound statement 无效的绑定问题

    问题 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 关于这个问题,我的是 Maven 项目,在访问程序的接口时,抛出异常信息,无效的绑定语句. 在检查调用的 Mapper 接口时,发现在目标文件中没有找到 Mapper 映射的配置文件,在项目的 target 目标文件中可以看到,与接口对应的 Mapper 文件未加载,所以在程序启动时,就找不到对应的映射文件,导致的这个错误. 解决

  • SpringBoot使用MyBatis-Plus解决Invalid bound statement异常

    目录 前言 缘由 解决问题 总结 前言 本篇文章主要介绍关于我在SpringBoot中使用MyBatis-Plus是如何解决Invalid bound statement (not found)这个异常的.我先抛一些我在这个途中遇到的一些问题,看看各位了解不了解. 当Mybatis的xml文件不在resouce下时该如何配置. 如何去指定mapper-Location的配置. classpath*跟classpath的区别是啥 Invalid bound statement (not found

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

    搭建项目时使用了mybatisplus,项目能够正常启动,但在调用mapper方法查询数据库时报Invalid bound statement (not found)错误. 以下为项目配置 pom文件 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-extension</artifactId> <version>3.3.0</versio

  • MybatisPlus BaseMapper 中的方法全部 Invalid bound statement (not found Error处理)

    错误梗概 接手了一个新任务,需要修改别人的代码.看看数据库配置 ,连连接池都没,然后引入了 druid,本来一切很顺利.后来不知道怎么回事,运行起来后总是报 "Invalid bound statement (not found) ",而且报错的都是 MybatisPlus 生成的 BaseMapper 中的方法,自己写的都能正常运行. 参考了很多其他帖子,都无果,最后弄了很久,终于搞定了,特级录之. druid 和 mybatis-plus 配置参数如下: pom.xml <d

  • 解决mybatis-plus通用mapper调用报错:Invalid bound statement

    目录 mybatis-plus通用mapper调用报错 解决方法 mybatis-plus通用mapper调用报错 使用springboot整合mybatis-plus后,调用自定义的方法正常,调用BaseMapper中自带的方法报错如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.rkang.enterprise.mapper.EmployeeInfoMapper.se

  • SpringBoot项目中分页插件PageHelper无效的问题及解决方法

    在Springboot项目中使用分页插件的时候 发现PageHelper插件失效了 我导入的是: 后来才发 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.10</version> </dependency> 现 PageHelper若要在Springbo

  • 解决IDEA的maven项目中没有新建Servlet文件的选项问题

    问题:右键package新建却没有servlet的选项 原因:项目设置里面没有勾选Source Roots 解决办法: Step1. Step2 到此这篇关于IDEA的maven项目中没有新建Servlet文件的选项问题及解决方法的文章就介绍到这了,更多相关IDEA maven项目没有新建Servlet文件的选项内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

随机推荐