mybatis遇到的Invalid bound statement (not found)

mybatis一个怪异的问题:
Invalid bound statement (not found): cn.com.dao.UserDao.selectByUser at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:178)    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38)    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)    at $Proxy22.selectByUser(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for cn.com.dao.UserDao.selectByUser
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615)    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608)    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:176)
    ... 34 more
1. 我检查了半天也没看出什么问题来,后来把mapper的xml select 语句重写。问题竟然好了。出了这种问题:
<mapper namespace="cn.com.dao.UserDao"> 

mapper的namespace写的不对!

<insert id="insert" parameterType="com.test.pojo.User" >

parameterType没有写对。

2. UserDao的方法在UserDao.xml中没有,然后执行UserDao的方法会报此错
3. 删除配置文件里中文的注释,保存.
4. Mybatis的自动扫描 错误
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
        <!-- 自动扫描mapping.xml文件 -->  
        <property name="mapperLocations" value="classpath:com/test/mapping/*.xml"></property>  
</bean>  

value=”classpath:com/test/mapping/*.xml”没有写对

<!-- DAO接口所在包名,Spring会自动查找其下的类 -->  
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
        <property name="basePackage" value="com.test.dao" />  
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
</bean>  

<property name=”basePackage” value=”com.test.dao” /> 没有写对

5. 如果你确认没有以上问题,请任意修改下对应的xml文件,比如删除一个空行,保存.问题解决…
    原文作者:尽心上
    原文地址: https://www.jianshu.com/p/acaf25a23a47
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞