【已解决】Invalid bound statement (not found)

报错讯息

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.casey.mapper.SysRoleMapper.getUserRoleCode
at org.apache.ibatis.binding.MapperMethod S q l C o m m a n d . < i n i t > ( M a p p e r M e t h o d . j a v a : 235 )   [ m y b a t i s − 3.5.4. j a r : 3.5.4 ] a t c o m . b a o m i d o u . m y b a t i s p l u s . c o r e . o v e r r i d e . M y b a t i s M a p p e r M e t h o d . < i n i t > ( M y b a t i s M a p p e r M e t h o d . j a v a : 50 )   [ m y b a t i s − p l u s − c o r e − 3.3.2. j a r : 3.3.2 ] a t c o m . b a o m i d o u . m y b a t i s p l u s . c o r e . o v e r r i d e . M y b a t i s M a p p e r P r o x y . l a m b d a SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.4.jar:3.5.4] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:50) ~[mybatis-plus-core-3.3.2.jar:3.3.2] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambda SqlCommand.<init>(MapperMethod.java:235) [mybatis3.5.4.jar:3.5.4]atcom.baomidou.mybatisplus.core.override.MybatisMapperMethod.<init>(MybatisMapperMethod.java:50) [mybatispluscore3.3.2.jar:3.3.2]atcom.baomidou.mybatisplus.core.override.MybatisMapperProxy.lambdacachedMapperMethod 0 ( M y b a t i s M a p p e r P r o x y . j a v a : 101 )   [ m y b a t i s − p l u s − c o r e − 3.3.2. j a r : 3.3.2 ] a t j a v a . u t i l . c o n c u r r e n t . C o n c u r r e n t H a s h M a p . c o m p u t e I f A b s e n t ( C o n c u r r e n t H a s h M a p . j a v a : 1660 )   [ n a : 1.8. 0 2 91 ] a t c o m . b a o m i d o u . m y b a t i s p l u s . c o r e . o v e r r i d e . M y b a t i s M a p p e r P r o x y . c a c h e d M a p p e r M e t h o d ( M y b a t i s M a p p e r P r o x y . j a v a : 100 )   [ m y b a t i s − p l u s − c o r e − 3.3.2. j a r : 3.3.2 ] a t c o m . b a o m i d o u . m y b a t i s p l u s . c o r e . o v e r r i d e . M y b a t i s M a p p e r P r o x y . i n v o k e ( M y b a t i s M a p p e r P r o x y . j a v a : 95 )   [ m y b a t i s − p l u s − c o r e − 3.3.2. j a r : 3.3.2 ] a t c o m . s u n . p r o x y . 0(MybatisMapperProxy.java:101) ~[mybatis-plus-core-3.3.2.jar:3.3.2] at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_291] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.java:100) ~[mybatis-plus-core-3.3.2.jar:3.3.2] at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:95) ~[mybatis-plus-core-3.3.2.jar:3.3.2] at com.sun.proxy. 0(MybatisMapperProxy.java:101) [mybatispluscore3.3.2.jar:3.3.2]atjava.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) [na:1.8.0291]atcom.baomidou.mybatisplus.core.override.MybatisMapperProxy.cachedMapperMethod(MybatisMapperProxy.java:100) [mybatispluscore3.3.2.jar:3.3.2]atcom.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:95) [mybatispluscore3.3.2.jar:3.3.2]atcom.sun.proxy.Proxy159.getUserRoleCode(Unknown Source) ~[na:na]
at com.casey.service.impl.SysRoleServiceImpl.isSuperAdmin(SysRoleServiceImpl.java:29) ~[classes/:na]

排查

  1. namespace 、id 和 文件名均正确
  2. 配置文件对应目录正确
mybatis-plus:
    type-aliases-package: com.casey.domain
    configuration:
        log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    mapper-locations: classpath:/mappers/*Mapper.xml

在这里插入图片描述
3. 编译后生成的 target 含有 xml 文件
在这里插入图片描述
4. maven clean 后,install
5. 重写 xml 文件
======================== 以上都没有用 ===========================
查看 git log,发现这段代码注释后就正常了。

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    //获取mybatis-plus全局配置
    GlobalConfig globalConfig = GlobalConfigUtils.defaults();
    //mybatis-plus全局配置设置元数据对象处理器为自己实现的那个
    globalConfig.setMetaObjectHandler(new AutoFillHandler());
    mybatisSqlSessionFactoryBean.setDataSource(dataSource);
    //mybatisSqlSessionFactoryBean关联设置全局配置
    mybatisSqlSessionFactoryBean.setGlobalConfig(globalConfig);
    return mybatisSqlSessionFactoryBean.getObject();
}

猜测是新的 mybatisSqlSession 覆盖了配置文件的 mapper 路径。

添加以下代码

// 设置 Mapper 文件的位置
Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath:mappers/*Mapper.xml");
mybatisSqlSessionFactoryBean.setMapperLocations(resources);

成功解决。

  • 29
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Caseythekiwi_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值