现象
调用接口报错
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里的方法,可能的原因:
- xml里的方法名跟Mapper里不一致
- xml里的命名空间与Mapper不一致
- 编译好的代码里缺失xml文件
- 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即可。