解决Maven项目中 Invalid bound statement 无效的绑定问题
作者:伟大的格尔夫斯 发布时间:2021-08-13 10:30:41
问题
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文件。
问题解决。
来源:https://blog.csdn.net/weixin_41016986/article/details/82226978


猜你喜欢
- 目录1、在异常处理中,如释放资源,关闭数据库、关闭文件应由( )语句来完成。2、如下Java语句 double x=2.0; int y=4
- 一、背景当前B/S模式已成为应用开发的主流,而在企业办公系统中,常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统、银行系
- 在使用foreach时,collection属性值的三种情况:如果传入的参数类型为List时,collection的默认属性值为list,同
- 全面解析java注解Java中的常见注解 a.JDK中的注解 @Override 覆盖父类或者父接口的方
- Java中java.io包为我们提供了输入流和输出流,对文件的读写基本上都依赖于这些封装好的关于流的类中来实现。前段时间遇到了以下两种需求:
- 电商项目中经常有这样的需求:在商品列表页面中,切换列表的展现形式,一般分为列表形式和表格形式。如京东:本文最终实现的效果:关键词:Recyc
- 在C#中,得益于强大的GC机制,使得我们开发程序变得非常简单,很多时候我们只需要管使用,而并不需要关心什么时候释放资源。但是,GC有的时并不
- 第一步 环境(UBUNTU系统下)sudo apt-get install mono-gmcs mono第二步 建立example.cscl
- 注意,本文所说的断点续传特指 HTTP 协议中的断点续传。本文主要聊聊思路和关键代码,更多细节请参考本文附带的 demo。工作原理HTTP
- 本文实例为大家分享了C#实现串口示波器的具体代码,供大家参考,具体内容如下开发工具visual studio2019C#串口示波器,实时刷新
- 本文实例为大家分享了Android刷新加载框架的具体代码,供大家参考,具体内容如下1.定义一个接口控制下拉和上拉public interfa
- 代码如下所示:<!-- 配置数据源 --> <bean id="dataSource" c
- 最近的项目里用到了,在网上找不到合适的,于是自己写了个简单的,带回弹效果:可以自定义的属性有:<!-- 滑动解锁控件 xml配置属性
- 1.类成员与方法的可见性最小化举例:如果是一个private的方法,想删除就删除如果一个public的service方法,或者一个publi
- 在进行java编程的时候,我们可以生成可运行的jar文件,但是鉴于平台的不同,我们可能需要将jar文件转化为exe格式。今天,小编就用一款叫
- 倒序拼接字符串@ApiOperation("分页查询") @GetMapping(value
- 如果是在资源文件里,可以这样写.< resources > <
- 本文实例为大家分享了Android微信摇一摇功能的实现方法,供大家参考,具体内容如下import java.util.ArrayList;
- 在Java中经常会涉及到对象数组的排序问题,那么就涉及到对象之间的比较问题。通常对象之间的比较可以从两个方面去看:第一个方面:对象的地址是否
- 测试代码pom.xml:<?xml version="1.0" encoding="UTF-8"