解决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异常处理自动配置的原理
Jun 21 Java/Android
详解Java线程池是如何重复利用空闲线程的
Jun 26 Java/Android
关于@OnetoMany关系映射的排序问题,使用注解@OrderBy
Dec 06 Java/Android
java objectUtils 使用可能会出现的问题
Feb 28 Java/Android
InterProcessMutex实现zookeeper分布式锁原理
Mar 21 Java/Android
关于EntityWrapper的in用法
Mar 22 Java/Android
SpringBoot中使用Redis作为全局锁示例过程
Mar 24 Java/Android
Netty客户端接入流程NioSocketChannel创建解析
Mar 25 Java/Android
Android自定义ScrollView实现阻尼回弹
Apr 01 Java/Android
Flutter Navigator 实现路由传递参数
Apr 22 Java/Android
阿里面试Nacos配置中心交互模型是push还是pull原理解析
Jul 23 Java/Android
Java中的Kafka为什么性能这么快及4大核心详析
Sep 23 Java/Android
解析Java异步之call future
分析Netty直接内存原理及应用
Jun 14 #Java/Android
详解JAVA中的OPTIONAL
解析Java中的static关键字
Java实现斗地主之洗牌发牌
MybatisPlus代码生成器的使用方法详解
教你用Java在个人电脑上实现微信扫码支付
You might like
Apache下禁止php文件被直接访问的解决方案
2013/04/25 PHP
PHP CLI模式下的多进程应用分析
2013/06/03 PHP
使用HMAC-SHA1签名方法详解
2013/06/26 PHP
ThinkPHP 表单自动验证运用示例
2014/10/13 PHP
PHP工程师VIM配置分享
2015/12/15 PHP
php使用pclzip类实现文件压缩的方法(附pclzip类下载地址)
2016/04/30 PHP
PHP+Ajax验证码验证用户登录
2016/07/20 PHP
PHP+mysql+ajax轻量级聊天室实现方法详解
2016/10/17 PHP
两个SUBMIT按钮,如何区分处理
2006/08/22 Javascript
js跑马灯代码(自写)
2013/04/17 Javascript
ExtJS4中使用mixins实现多继承示例
2013/12/03 Javascript
获取当前点击按钮的id用this.id实现
2014/03/17 Javascript
jQuery中delegate()方法用法实例
2015/01/19 Javascript
JS+CSS实现模仿浏览器网页字符查找功能的方法
2015/02/26 Javascript
JS实现图片局部放大或缩小的方法
2016/08/20 Javascript
js实现表单提交后不重新刷新当前页面
2016/11/30 Javascript
JS 循环li添加点击事件 (闭包的应用)
2016/12/10 Javascript
谈谈Vue.js——vue-resource全攻略
2017/01/16 Javascript
Angular企业级开发——MVC之控制器详解
2017/02/20 Javascript
Node.js五大应用性能技巧小结(必须收藏)
2017/08/09 Javascript
vue 引入公共css文件的简单方法(推荐)
2018/01/20 Javascript
解决npm管理员身份install时出现权限的问题
2018/03/16 Javascript
详解vue使用$http服务端收不到参数
2019/04/19 Javascript
javascript面向对象三大特征之多态实例详解
2019/07/24 Javascript
浅谈vue-props的default写不写有什么区别
2020/08/09 Javascript
Python实现使用卷积提取图片轮廓功能示例
2018/05/12 Python
flask入门之表单的实现
2018/07/18 Python
python-opencv颜色提取分割方法
2018/12/08 Python
TensorFlow卷积神经网络之使用训练好的模型识别猫狗图片
2019/03/14 Python
pytorch动态网络以及权重共享实例
2020/01/06 Python
Python列表解析操作实例总结
2020/02/26 Python
浅谈Python xlwings 读取Excel文件的正确姿势
2021/02/26 Python
武汉瑞得软件笔试题
2015/10/27 面试题
货车司机岗位职责
2014/03/18 职场文书
企业安全生产目标责任书
2014/07/23 职场文书
一文搞懂php的垃圾回收机制
2021/06/18 PHP