org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
2017-01-14 12:42
519 查看
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上,需要比较细致的对比,我经常就是写错了一两个字母搞的很长时间找不到错误
按以下步骤一一执行:
1:检查xml文件所在的package名称是否和interface对应的package名称一一对应
2:检查xml文件的namespace是否和xml文件的package名称一一对应
3:检查函数名称能否对应上
4:去掉xml文件中的中文注释
5:随意在xml文件中加一个空格或者空行然后保存
一般来说到此就可以排除错误了。
以上步骤除第5步,其他步骤没什么问题。第5步看起来这么怪异的解决方式,实际上是触发了ide的自动编译功能。由于xml文件在编译的时候,不一定总能立即从源目录复制到class文件的编译目录(MyEclipse经常出这个问题),有时候你源目录中的xml文件已经修改好了,而class所在的目录里面还是旧的。因此真正确定有效的方式是将正确的xml文件复制到class输出目录。
还有种情况会出这个错误,比如配置xml映射文件需要满足特定要求
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:mybatis-config.xml">
<property name="mapperLocations">
<list>
<value>classpath*:mapper/com/xxx/**/*Mapper.xml</value>
<value>classpath*:dao/com/xxx/**/*Mapper.xml</value>
</list>
</property>
</bean>
如上只有Mapper结尾的xml文件才会被Mybatis扫描到,这个时候如果忘记了这个规则,xml使用了其他名称,如xxxDao.xml。这样xml的配置就不会加入到Mybatis存储配置的一个map对象里去,也会出现 Invalid bound statement 的错误。解决方法就是把xml文件改名即可。
一般的原因是Mapper interface和xml文件的定义对应不上,需要检查包名,namespace,函数名称等能否对应上,需要比较细致的对比,我经常就是写错了一两个字母搞的很长时间找不到错误
按以下步骤一一执行:
1:检查xml文件所在的package名称是否和interface对应的package名称一一对应
2:检查xml文件的namespace是否和xml文件的package名称一一对应
3:检查函数名称能否对应上
4:去掉xml文件中的中文注释
5:随意在xml文件中加一个空格或者空行然后保存
一般来说到此就可以排除错误了。
以上步骤除第5步,其他步骤没什么问题。第5步看起来这么怪异的解决方式,实际上是触发了ide的自动编译功能。由于xml文件在编译的时候,不一定总能立即从源目录复制到class文件的编译目录(MyEclipse经常出这个问题),有时候你源目录中的xml文件已经修改好了,而class所在的目录里面还是旧的。因此真正确定有效的方式是将正确的xml文件复制到class输出目录。
还有种情况会出这个错误,比如配置xml映射文件需要满足特定要求
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:mybatis-config.xml">
<property name="mapperLocations">
<list>
<value>classpath*:mapper/com/xxx/**/*Mapper.xml</value>
<value>classpath*:dao/com/xxx/**/*Mapper.xml</value>
</list>
</property>
</bean>
如上只有Mapper结尾的xml文件才会被Mybatis扫描到,这个时候如果忘记了这个规则,xml使用了其他名称,如xxxDao.xml。这样xml的配置就不会加入到Mybatis存储配置的一个map对象里去,也会出现 Invalid bound statement 的错误。解决方法就是把xml文件改名即可。
相关文章推荐
- (原创)常见报错不常见原因之——org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Maven 遇到mybatis 发生org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- mybatis出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误
- nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- MyBatis笔记----报错:Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)解决方法
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.superr.powerful
- 关于mybatis的org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- spring+mybatis整合报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.png.mapper.User
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.evun.qns.gpis.pr
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)新的异常解决方案
- 【异常】Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- 解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)