【排错日记】mybatis之Invalid bound statement (not found)

文章讲述了在遇到Mybatis调用接口报错,具体表现为Invalidboundstatement(notfound)时,作者通过分析确认问题在于mybatis未能正确解析xml文件的路径。通过检查发现配置的资源路径与实际xml文件路径不符,修正后的解决方案是将资源路径改为classpath:mapper/**/.xml。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

现象

调用接口报错

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): xxxxxxx
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:51)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda$cachedInvoker$0(MybatisMapperProxy.java:111)
	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
	at com.baomidou.mybatisplus.core.toolkit.CollectionUtils.computeIfAbsent(CollectionUtils.java:117)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedInvoker(MybatisMapperProxy.java:98)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
	at com.sun.proxy.$Proxy306.getMonitorBill4ApiCode(Unknown Source)

分析

这个本质是找不到对应xml里的方法,可能的原因:

  1. xml里的方法名跟Mapper里不一致
  2. xml里的命名空间与Mapper不一致
  3. 编译好的代码里缺失xml文件
  4. mybatis配置文件配置的xml解析路径不对

验证

逐一排查,发现如下:

bean.setDataSource(dataSource);
bean.setPlugins(this.mybatisPlusInterceptor());
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resource = resolver.getResources("classpath:mapper/*.xml");
bean.setMapperLocations(resource);

其中,【classpath:mapper/*.xml】与xml的实际文件路径【src/main/resources/mapper/order/order.xml】无法匹配上,导致mybatis无法真正解析到,符合分析中的第4条。

修正

将【classpath:mapper/.xml】改为classpath:mapper/**/.xml即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白萝卜弟弟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值