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; }
未经允许 禁止转载
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具