springboot整合mytatis报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

学习springboot整合mytatis时,运行报错

org.apache.ibatis.binding.BindingException: Invalid bound statement
(not found): com.xbt.mapper.UsersMapper.add at
org.apache.ibatis.binding.MapperMethod S q l C o m m a n d . < i n i t > ( M a p p e r M e t h o d . j a v a : 214 )   [ m y b a t i s − 3.4.0. j a r : 3.4.0 ] a t o r g . a p a c h e . i b a t i s . b i n d i n g . M a p p e r M e t h o d . < i n i t > ( M a p p e r M e t h o d . j a v a : 48 )   [ m y b a t i s − 3.4.0. j a r : 3.4.0 ] a t o r g . a p a c h e . i b a t i s . b i n d i n g . M a p p e r P r o x y . c a c h e d M a p p e r M e t h o d ( M a p p e r P r o x y . j a v a : 59 )   [ m y b a t i s − 3.4.0. j a r : 3.4.0 ] a t o r g . a p a c h e . i b a t i s . b i n d i n g . M a p p e r P r o x y . i n v o k e ( M a p p e r P r o x y . j a v a : 52 )   [ m y b a t i s − 3.4.0. j a r : 3.4.0 ] a t c o m . s u n . p r o x y . SqlCommand.<init>(MapperMethod.java:214) ~[mybatis-3.4.0.jar:3.4.0] at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) ~[mybatis-3.4.0.jar:3.4.0] at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) ~[mybatis-3.4.0.jar:3.4.0] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.4.0.jar:3.4.0] at com.sun.proxy. SqlCommand.<init>(MapperMethod.java:214) [mybatis3.4.0.jar:3.4.0]atorg.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) [mybatis3.4.0.jar:3.4.0]atorg.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) [mybatis3.4.0.jar:3.4.0]atorg.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) [mybatis3.4.0.jar:3.4.0]atcom.sun.proxy.Proxy56.add(Unknown
Source) ~[na:na]

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.coyote.AbstractProtocol C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 790 ) [ t o m c a t − e m b e d − c o r e − 8.5.27. j a r : 8.5.27 ] a t o r g . a p a c h e . t o m c a t . u t i l . n e t . N i o E n d p o i n t ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.27.jar:8.5.27] at org.apache.tomcat.util.net.NioEndpoint ConnectionHandler.process(AbstractProtocol.java:790)[tomcatembedcore8.5.27.jar:8.5.27]atorg.apache.tomcat.util.net.NioEndpointSocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.27.jar:8.5.27]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.27.jar:8.5.27]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor W o r k e r . r u n ( T h r e a d P o o l E x e c u t o r . j a v a : 617 ) [ n a : 1.8. 0 4 5 ] a t o r g . a p a c h e . t o m c a t . u t i l . t h r e a d s . T a s k T h r e a d Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_45] at org.apache.tomcat.util.threads.TaskThread Worker.run(ThreadPoolExecutor.java:617)[na:1.8.045]atorg.apache.tomcat.util.threads.TaskThreadWrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.27.jar:8.5.27]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]

使用的工具为IDEA,项目结构如下: 将mapper接口和mapper.xml文件按照mybatis默认的方式放在一起,接口名与Mybatis的映射文件名保持一模一样,方便mybatis进行扫描

关于org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题原因可大致分为两种:

一、 mybatis的xxxMapper接口与xxxMapper.xml接口没映射成功可细分为如下几种原因
  1. xxxMapper.xml中的namespace是否绑定到对应的xxxMapper.java接口在这里插入图片描述
  2. xxxMapper.xm语句中的id在xxxMapper.java中是否有方法声明与之对应在这里插入图片描述
    3.配置的扫描xxxMapper.java接口类的包名是否正确在这里插入图片描述
    4.检查接口中的返回值是否和xml中的ResultType一致,排除返回值装配错误问题。
    5.还有些其mybatis配置文件和接口类书写方面的细节原因不再一一赘述
二、 (本人遇到的问题)maven项目的编译问题,导致编译后文件下没有包括xxxMapper.xml文件

maven 默认只把 src/main/java 中的.java文件进行编译到class中以及 src/main/resources 里面的非.java 文件(.xml/.properties/…)进拷贝到classes 中。若想要把src/main/java 中的.xml文件拷贝至编译目录(classes)
解决办法:在pom文件中添加下列配置(再到编译目录(classes)下查看,此时已有xml文件,问题也得到解决)

 <build>
   <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>**/*.xml</includes>
        </resource>

    </resources>  
 </build>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值