spring boot 整合mybatis org.apache.ibatis.binding.BindingException: Invalid bound statement(not found)

今天写spring boot 整合mybatis的时候遇到org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)这个错,找了很久,总结原因是因为扫描不到xxxMapper.xml。

受到以前整个springMvc整合mybatis的影响,将文件放在了src/main/java下,导致一直扫描不到xxxMapper.xml文件。原因是:idea中maven打包的时候不会将xxxMapper.xml,所以target打包之后不会有xxxMapper.xml文件,所以一直扫描不到。

目录结构:

这里写图片描述

解决办法:将xxxMapper.xml文件放在了src/main/resources下,然后在application.properties文件中添加配置

mybatis.mapper-locations=classpath:mappings/*.xml

或者在application.yml文件中加入配置:

mybatis:
  mapper-locations: classpath:mappings/*.xml

还有一种办法是:

使用@Select、@Insert、@Update、@Delete注解代替xxxMapper.xml里面的内容,这样就不存在扫描xxxMapper.xml文件的问题了。

遇到org.apache.ibatis.binding.BindingException: Invalid bound statement(not found)这个问题可能还有其他原因,不过这些原因很容易排查。

  1. xxxMapper.xml文件中的namespace对应有误
  2. xxxMapper.java文件中没有对应的xxxMapper.xml中的方法。

记录一下,防止以后自己再采坑。:)

  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 29
    评论
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值