mybatis的Invalid bound statement (not found)

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

解释:就是说,你的Mapper接口,被Spring注入后,却无法正常的使用mapper.xml的sql;
这里的Spring注入后的意思是,你的接口已经成功的被扫描到,但是当Spring尝试注入一个代理(MyBatista实现)的实现类后,却无法正常使用。这里的可能发生的情况有如下几种;

接口已经被扫描到,但是代理对象没有找到,即使尝试注入,也是注入一个错误的对象(可能就是null)
接口已经被扫描到,代理对象找到了,也注入到接口上了,但是调用某个具体方法时,却无法使用(可能别的方法是正常的)
当然,我们不好说是那种情况,毕竟报错的结果是一样的,这里就提供几种排查方法:

mapper接口和mapper.xml是否在同一个包(package)下?名字是否一样(仅后缀不同)?
比如,接口名是NameMapper.java;对应的xml就应该是NameMapper.xml
mapper.xml的命名空间(namespace)是否跟mapper接口的包名一致?
比如,你接口的包名是com.abc.dao,接口名是NameMapper.java,那么你的mapper.xml的namespace应该是com.abc.dao.NameMapper
接口的方法名,与xml中的一条sql标签的id一致
比如,接口的方法List<User> findAll();那么,对应的xml里面一定有一条是<select id="findAll" resultMap="**">****</select>
如果接口中的返回值List集合(不知道其他集合也是),那么xml里面的配置,尽量用resultMap(保证resultMap配置正确),不要用resultType
最后,如果你的项目是maven项目,请你在编译后,到接口所在目录看一看,很有可能是没有生产对应的xml文件,因为maven默认是不编译的,因此,你需要在你的pom.xml的<build></build>里面,加这么一段:

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

原文地址:https://www.cnblogs.com/longyao/p/11731070.html

时间: 2024-08-29 19:05:53

mybatis的Invalid bound statement (not found)的相关文章

mybatis中Invalid bound statement (not found) 和 Result Maps collection already contains value for...错误解决方案

一.Invalid bound statement (not found) 使用mybatis有时候会报Invalid bound statement (not found)这种错误,总结了下,可能有两种情况如下: 1.mybatis的对应的mapper.xml找不到对应的命名sql或者名称与mapper接口名称不一致. 2.xml文件与接口名称都对,但是在mybatis配置文件中漏掉了配置,也会报这种错误. 二.Result Maps collection already contains v

解决Mybatis的invalid bound statement (not found)异常

使用Maven构建SSM时, 需要在pom.xml中配置一些信息, 否则mapper.xml就无法被扫描到, 程序就会抛invalid bound statement (not found)异常 解决办法: 将下面配置添加到pom.xml文件中 1 <build> 2 <resources> 3 <resource> 4 <directory>src/main/java</directory> 5 <includes> 6 <i

关于 Mybatis 的Invalid bound statement (not found):错误

今天遇到一个特别奇怪的问题,最后发现是自己对mybatis的学习还有待提高 返回类型可以用resultType,也可以用resultMap resultType是直接表示返回类型的,而resultMap则是对外部ResultMap的引用 举个例子: resultMap: <select id="findByContract" resultMap="BaseResultMap">        select        *        from    

idea的spring整合基于xml文件配置的mybatis报Invalid bound statement (not found): com.music.dao.MusicDao.findAll的问题

一. 题主当时就是自己尝试整合spring和mybatis的时候遇到了这个问题,当时题主只看到了用注解的方式配置的dao层,题主用的是xml文件配置的形式, 而且坑爹的是题主的两个文件的路径写的也不一致,就导致直接用<property name="basePackage" value="com.music.dao"></property> 导致绑定异常 后来在网上查到了解决的办法 ,就是如果路径一致,(如果一致你也就不会来看到本文了), 两个

mybatis plus Invalid bound statement (not found) 解决方案

常规的解决方案见:https://www.cnblogs.com/shaoyu/p/11477125.html 问题:当xml文件在src/main/java目录下时,在application.yml中配置Mapper文件路径无效,当xml文件在resource下时路径有效,原因不明. 我通过上面连接提到的所有的方法都无法解决遇到的问题.可能是mybatis plus的特殊性造成的,在参考其他人的解决方案的情况下, 终于解决了这个问题,解决方案如下: 重新在SqlSessionFactory中指

关于mybatis Invalid bound statement (not found) 问题

初学mybatis   现在系统是spring + mybatis  applicationContext.xml里面配置了Mapper 自动扫描 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">    <property name="basePackage" value="com.yolly.platform.*" /></bean&g

转载:Maven项目mybatis Invalid bound statement (not found)解决方法

在mapper代理的开发中,程序员需要遵守一些规范,mybatis才能实现mapper接口的代理对象. 它的规范如下: mapper.xml的namespace要写所映射接口的全称类名. mapper.xml中的每个statement的id要和接口方法的方法名相同 mapper.xml中定义的每个sql的parameterType要和接口方法的形参类型相同 mapper.xml中定义的每个sql的resultType要和接口方法的返回值的类型相同 mapper.xml要和对应的mapper接口在

Mybatis 异常记录(1): Invalid bound statement (not found)

错误信息: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pingan.credit.dao.mapper.TdReportMapper.insertQueryLog at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:223) at org.apache.ibatis

MyBatis笔记----报错Exception in thread &quot;main&quot; org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectUser

信息: Refreshing org[email protected]41cf53f9: startup date [Wed Apr 05 16:48:12 CST 2017]; root of context hierarchy 四月 05, 2017 4:48:12 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definiti