BindingException: Invalid bound statement (not found): com.*..Mapper.get源码分析

2 篇文章 0 订阅
2 篇文章 0 订阅

问题分析

https://blog.csdn.net/msu9527/article/details/119059103

源码分析

2021-07-21 16:03:35.539 169254213631626854594179000022164 http-nio-8005-exec-4 ERROR c.a.f.c.a.ExceptionAdvice:27 - /user/list
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.*.Mapper.get
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
	at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
	at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:61)
	at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
	at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:61)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:56)
	at com.sun.proxy.$Proxy206.get(Unknown Source)

查看报错代码位置(正常下图 ms 应该是会有值的):
mapper 方法执行ms

正常mybatis 启动

正常mybatis 启动执行 org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration#sqlSessionFactory

自动加载mapper/*.xml 中的文件

mybatis启动加载类

启动时在类SqlSessionFactoryBean.class 的mapperLocations 加断点, 查看加载的xml文件:
注:这里是2.0.2.jar 不同版本位置可能不同,找到org.mybatis.spring.SqlSessionFactoryBean#buildSqlSessionFactory 方法中mapperLocations 即可
mybatis加载Mapper.xml

执行接口时:正常下图中ms 是不会为空的,启动时所有的xml 像上图被加载到,所以报错有可能是启动时加载不到
org.apache.ibatis.binding.MapperMethod.SqlCommand#SqlCommand
mabatis-sql执行ms

mybatis-plus 启动

执行方法:com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusAutoConfiguration#sqlSessionFactory
mybatis-plus 执行文件

由于值this.properties.resolveMapperLocations() 为空,不会进来下面的方法

if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
            factory.setMapperLocations(this.properties.resolveMapperLocations());
        }

然后在下面文件就看不到 mapperLocations 的值

com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean#buildSqlSessionFactory
mybatis-plus 执行sql ms为空

这里就是我的报错原因,引入了新的依赖导致应用启动时走了mybatis-plus 的类,而并没有配置mapper xml 的地址,所以执行mapper 接口时 报ms找不到,直接把依赖exclusion 掉或者添加mapper配置

mybatis-plus 指定mapper 方法,官方示例
mybatis-plus官网示例
或者yml 配置

mybatis-plus:
  mapper-locations: classpath:mapper/**/**Mapper.xml
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在你的问题中,出现了一个异常错误信息:"org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.wn.mapper.EmployeeMapper.get"。根据引用中的提示信息,这个错误是由于MyBatis-Plus持久化框架中的Mapper.javaMapper.xml绑定失败导致的。换句话说,可能在Mapper.xml中没有找到对应的方法与Mapper.java中的方法进行绑定,导致无法找到相关的操作。 当业务操作流转到Mapper.xml时,如果找不到对应的绑定关系,就会出现这个错误。而如果业务调用没有流转到Mapper.xml中,就不会触发这个错误。 为了解决这个问题,你可以检查以下几个方面: 1. 确保Mapper.java中的方法与Mapper.xml中的方法名称和参数一致。 2. 检查Mapper.xml中是否存在对应的方法,需要注意方法名、参数和返回值类型是否正确。 3. 确保Mapper.xml文件已经正确配置到MyBatis的配置文件中。 通过检查以上几个方面,你应该能够解决这个错误。如果问题仍然存在,你可以进一步检查MyBatis-Plus的文档和相关配置,或者向MyBatis-Plus的社区寻求帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.xxx 的解决...](https://blog.csdn.net/Hello_World_QWP/article/details/126713075)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值