MybatisPlus自带方法报错BindingException: Invalid bound statement (not found)

问题描述:
MybatisPlus自带方法如 xxx.list() xxx.save() 或则xxMapper.selectList()...
等方法无法使用报错:Invalid bound statement (not found)
但是自己定义的sql方法可以使用
问题排查:
1、自定义方法可使用 排除xml位置不正确,包扫描没扫到(target目录下已生成对应的mapper和xml文件)
2、检查mybatis-plus.mapper-locations=classpath:mapper/*/*.xml 配置没问题
3、检查自定义配置代码:

@Bean(name = "mysqlSqlSessionFactory")
public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/mysql/*.xml"));
return bean.getObject();
}

找到问题:SqlSessionFactory是MyBatis的类,MybatisPlus应该使用MybatisSqlSessionFactoryBean

问题修复:

@Bean(name = "mysqlSqlSessionFactory")
public MybatisSqlSessionFactoryBean mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/mysql/*.xml"));
return bean;
}

未经允许 禁止转载

posted @   java从精通到入门  阅读(1064)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示