- Invalid bound statement (not fou
- Invalid bound statement (not fou
- Invalid bound statement (not fou
- Invalid bound statement (not fou
- invalid bound statement (not fou
- Invalid bound statement (not fou
- Invalid bound statement (not fou
- invalid bound statement (not fou
- invalid bound statement (not fou
- Invalid bound statement (not fou
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.dao.XxxMapper
Invalid bound statement
这个异常相信有点开发经验的人都不陌生吧,尤其是整天跟Mybatis打交道的,或多或少都会遇到过.
然后请教同事或者自己百度, 找到症结所在, 也都迈过去了.
不幸的是, 我今天又掉到这个坑里去了, 而且爬了一晚上没爬出来
该异常能百度出来的解决方案就不说了, 大家随便一搜就能找见,
还是说一下吧, 免得你们再去百度了
如果是Spring + MyBatis, 检查Spring配置文件中org.mybatis.spring.SqlSessionFactoryBean的mapperLocations属性是否配置正确, 以及org.mybatis.spring.mapper.MapperScannerConfigurer的basePackage属性是否配置正确.

SpringBoot + MyBatis, 检查 配置文件中的mybatis.mapper-locations配置项(多个路径可用","隔开), 以及程序入口类上的@MapperScan注解是否包含了需要被扫描到的Mapper接口所在的包名


XxxMapper.xml文件中namespace属性是否对应 XxxMapper接口的全类名, XxxMapper.xml文件中的resultType是都对应相应实体Bean的全类名


以上配置项配置正确, 应该可以解决90%的Invalid bound statement
除非 像我遇到的坑一样 心血来潮, 非要把Mapper.xml和Mapper接口放在同一个包下,
源码跟踪的细节就不细细展开了, 有兴趣的可以在PathMatchingResourcePatternResolver这个类的doFindPathMatchingFileResources方法的try代码块中打个断点跟踪一下.
说解决办法. 项目的pom文件中的<build>节点内添加<resources>节点, 节点内容如下

主要起什么作用解释一下:
如果XxxMapper.xml和XxxMapper.java放置在同包下, 不加上述配置, 则在项目编译XxxMapper.java后生成的XxxMapper.class路径下是不存在XxxMapper.xml的,
也即上面的配置项即使是配置的准确无误, 最后也会在PathMatchingResourcePatternResolver这个类的doFindPathMatchingFileResources方法中报Mapper接口映射文件找不到的IO异常
由于只扫到了Mapper接口, 没有扫到Mapper.xml配置文件, 最终导致报出文章开头的异常
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.dao.XxxMapper
网友评论