【已解决】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.(MapperMethod.java:235) ~[mybatis-3.5.4.jar:3.5.4] at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.(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

【已解决】Invalid bound statement (not found)_第1张图片
3. 编译后生成的 target 含有 xml 文件
【已解决】Invalid bound statement (not found)_第2张图片
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);

成功解决。

你可能感兴趣的:(mybatis,maven,springboot,java,服务器,微服务,xml)