关于出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误的一些解决思路
错误信息:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
解决方案
1、首先尝试以下方案
1、检查xml文件所在的package名称是否和接口对应的package名称一一对应
2、检查xml文件的namespace是否和xml文件的package名称一一对应
3、检查函数名称能否对应上
4、去掉xml文件中的中文注释
5、随意在xml文件中加一个空格或者空行然后保存
2、idea的pom文件问题
在使用IDEA开发时,如果打包时*Mapper.xml没有自动复制到class输出目录的mapper类包下,则需要在pom文件中添加mybatis加载配置文件的配置!
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
3、mybatis和其他框架整合时
spring的配置文件中的
<!--spring 开启自动扫描-->
<context:component-scan base-package="day11" />
<!--mybatis 扫描dao-->
<mybatis:scan base-package="day11.dao"/>
<!--配置dao的领一种方法-->
<!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="day11.dao"/>
</bean>-->
<!--整合-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:*/FileDao.xml" />
</bean>
这里的 mybatis:scan
或 MapperScannerConfigurer
必须要声明到dao层,否则就会出现绑定失败的错误,本人就是犯了这个错。
另注意
:
在eclipse中进行整合时千万要写清楚 sqlSessionFactory 中的 mapperLocations 的路径,错误路径:classpath*:FileDao.xml
这样的路径在eclipse中不会报错可以找到,而idea中会报错,必须写成 classpath*:*/FileDao.xml`也就是必须声明包名,否则也会造成绑定失败。