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


Posted in Java/Android onJune 15, 2021

问题

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

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

关于这个问题,我的是 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有没有编译出来,看了之后一目了然。

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

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

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

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

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

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

问题解决。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Java/Android 相关文章推荐
解决SpringBoot文件上传临时目录找不到的问题
Jul 01 Java/Android
springboot+WebMagic+MyBatis爬虫框架的使用
Aug 07 Java/Android
SpringBoot整合Mybatis Generator自动生成代码
Aug 23 Java/Android
OpenCV实现反阈值二值化
Nov 17 Java/Android
Java练习之潜艇小游戏的实现
Mar 16 Java/Android
Android基于Fresco实现圆角和圆形图片
Apr 01 Java/Android
Java 定时任务技术趋势简介
May 04 Java/Android
springcloud整合seata
May 20 Java/Android
springboot为异步任务规划自定义线程池的实现
Jun 14 Java/Android
Java实现字符串转为驼峰格式的方法详解
Jul 07 Java/Android
Java代码规范与质量检测插件SonarLint的使用
Aug 05 Java/Android
httpclient调用远程接口的方法
Aug 14 Java/Android
解析Java异步之call future
分析Netty直接内存原理及应用
Jun 14 #Java/Android
详解JAVA中的OPTIONAL
解析Java中的static关键字
Java实现斗地主之洗牌发牌
MybatisPlus代码生成器的使用方法详解
教你用Java在个人电脑上实现微信扫码支付
You might like
海贼王动画变成“真人”后,凯多神还原,雷利太帅了!
2020/04/09 日漫
win7+apache+php+mysql环境配置操作详解
2013/06/10 PHP
简单的php新闻发布系统教程
2014/05/09 PHP
PHP生成唯一订单号
2015/07/05 PHP
PHP中的多种加密技术及代码示例解析
2016/10/20 PHP
php取出数组单个值的方法
2018/03/12 PHP
JavaScript 学习小结(适合新手参考)
2009/07/30 Javascript
JS中setTimeout()的用法详解
2013/04/14 Javascript
web css实现整站样式互相切换
2013/10/29 Javascript
js 针对html DOM元素操作等经验累积
2014/03/11 Javascript
jQuery中[attribute^=value]选择器用法实例
2014/12/31 Javascript
js淡入淡出焦点图幻灯片效果代码分享
2015/09/08 Javascript
jQuery+CSS3实现仿花瓣网固定顶部位置带悬浮效果的导航菜单
2016/09/21 Javascript
js多个物体运动功能实例分析
2016/12/20 Javascript
vue中轮训器的使用
2019/01/27 Javascript
基于javascript实现贪吃蛇小游戏
2019/11/25 Javascript
vue路由传参的基本实现方式小结【三种方式】
2020/02/05 Javascript
ant design vue 表格table 默认勾选几项的操作
2020/10/31 Javascript
vue中父子组件的参数传递和应用示例
2021/01/04 Vue.js
Vue过滤器,生命周期函数和vue-resource简单介绍
2021/01/12 Vue.js
Vue实现多页签组件
2021/01/14 Vue.js
python利用paramiko连接远程服务器执行命令的方法
2017/10/16 Python
详解pandas数据合并与重塑(pd.concat篇)
2019/07/09 Python
Django用户认证系统 组与权限解析
2019/08/02 Python
学习Python列表的基础知识汇总
2020/03/10 Python
关于python 的legend图例,参数使用说明
2020/04/17 Python
Python基于pandas爬取网页表格数据
2020/05/11 Python
关于HTML5你必须知道的28个新特性,新技巧以及新技术
2012/05/28 HTML / CSS
Canvas 帧动画吃苹果小游戏
2020/08/05 HTML / CSS
Java的for语句中break, continue和return的区别
2013/12/19 面试题
如何获取某个日期是当月的最后一天
2013/12/05 面试题
大学生毕业求职找工作的自我评价
2013/09/29 职场文书
学雷锋月活动总结
2014/04/25 职场文书
学校与家长安全责任书
2014/07/23 职场文书
学校开学标语
2014/10/06 职场文书
学生会主席任命书
2015/09/21 职场文书