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文件,比如刪除一個空行,保存.問題解決...
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容