BindingException: Invalid bound statement (not found)问题排查:SpringBoot集成Mybatis重点分析...
重构代码,方法抛出异常:BindingException: Invalid bound statement (not found)
提示信息很明显:mybatis没有提供某方法
先不解释问题原因和排查过程,因为使用SpringBoot集成Mybatis,主要配置点如下:
MyBatis 的真正强大在于它的映射器Mapper,它是开发者用于绑定映射语句(sql)的接口,而映射语句常规两种写法:annotation 和 xml 配置;
如果单纯使用annotation的方式,最主要是关心mapper java文件;
但是我们推荐sql配置在xml中,强大的逻辑判断、字段映射、sql复用...
1、mapper xml文件的扫描
如果使用xml配置sql,需要告诉SpringBoot扫描这些xml,常用以下两种配置方法
方法一:配置文件指定扫描路径(推荐)
1 mybatis: 2 mapper-locations: classpath:mapping/*.xml #注意:一定要对应mapper映射xml文件的所在路径 3 type-aliases-package: com.winter.model # 注意:对应实体类的路径
方法二:配置 SqlSessionFactory
Mybatis万能的SqlSessionFactory接口(还有一个SqlSession接口,他俩是mybatis的核心),直接在他里面指定xml路径
@Autowired @Bean public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource,PageHelper pageHelper) throws IOException {SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();sqlSessionFactoryBean.setDataSource(dataSource);/** 添加mapper 扫描路径 */PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/sql/*.xml";sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(packageSearchPath));/** 设置datasource */sqlSessionFactoryBean.setDataSource(dataSource);sqlSessionFactoryBean.setPlugins(new Interceptor[] { pageHelper });return sqlSessionFactoryBean; }
2、mapper接口的扫描
mapper接口是真正的java接口,使用动态代理,虽然只是接口定义,却实现了真正的sql执行、响应结果映射封装等,需要告诉SpringBoot扫描这些mapper接口,常用以下两种配置方法
方法一:接口上添加注解(推荐)
@Mapper public interface PermissionMapper {... 略 ... }
方法二:指定扫描包路径
@MapperScan("com.XXX.XXX.services.mapper")
总之,SpringBoot中注意xml和mapper接口的扫描配置。
出现:BindingException: Invalid bound statement (not found) 这种异常,问题排查步骤:
1、先确认如上两个配置是否正常;
2、检查mapper文件,方法是否存在
3、检查xml文件,id=方法名 的sql是否存在,该xml对应的mapper接口是否存在
注意:
如果sql通过annotation注解写在mapper接口上,同时也使用了xml的方式,注意id不能重复,即使参数完全不同,id也必须不同(mybatis的xml里面可没有override的概念)
相同的id只能存在不同的namespace里面
转载于:https://www.cnblogs.com/huahua035/p/10345382.html
BindingException: Invalid bound statement (not found)问题排查:SpringBoot集成Mybatis重点分析...相关推荐
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyh.springboot.
超详细-springboot+mybatisplus使用xml找不到mapper的解决办法 org.apache.ibatis.binding.BindingException: Invalid bo ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zzq.springboot.
这个bug的原因大多都是代码和xml配置文件没配对好.如果你和我一样,使用Spring boot + mybatis 开发,同时也是全程使用注解,你可以看看我的解决方案! 出现问题: org.apac ...
- (原创)常见报错不常见原因之——org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
错误日志:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)..... 常见原因:由于myb ...
- 解决:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) ...
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. org.apache.ibatis.binding.BindingException: Invali ...
- 【踩坑】遇到 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 报错...
今天在重做 iblog 客户端时,测试接口情况,发现了 org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.xxx.xxx 的解决办法
问题概述 关于这个问题,博主是在团队成员搭建基础框架的时候遇到的,协助团队成员解决,这儿记录下来仅供参考, 基础架构搭建,接口链路调用时, 程序报错:" org.apache.ibatis. ...
- BindingException: Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com...UserInfoMappe ...
- mybatis配置时出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)...
如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...
- mybatis-plus自定义mapper报org.apache.ibatis.binding.BindingException: Invalid bound statement(not found)
今天在springboot的项目中,需要用到自定义的mapper,之前一直使用mybatis-plus自动生成的mapper,一直可以正常使用,今天因为需求需要,自定义了mapper,但是一直报这个错 ...
最新文章
- [导入][转]好企业是什么样?
- 利用交换机解决局域网ARP问题(51CTO博客出书活动)
- nbu 196错误和191错误解析
- 【错误记录】发布 Flutter 插件包报错 ( ‘gmail.com‘ has insufficient permissions to upload new versions of package)
- Java - 为什么要使用接口编程【转】
- SpringBoot:class path resource [xxxx.xml] cannot be opened because it does not exist
- 高级特性(2)- XML
- boost::enable_shared_from_this相关的测试程序
- 【计算机网络】聊一聊那些常见的网络通信的性能指标
- 5位最具影响力的程序员
- 38、JAVA_WEB开发基础之下载功能
- Python系列文章
- 基于汇编语言及Proteus仿真的CPU8086水库水位监视系统
- 数论二(hdoj 卡特兰数)
- [CSS揭秘]不规则投影
- VSCODE如何汉化成中文
- ubuntu16.04系统安装nvidia显卡驱动
- 安卓逆向 -- AndroidKiller介绍
- eggs和egg是什么意思_eggs是什么意思_eggs的翻译_音标_读音_用法_例句_爱词霸在线词典...
- 微信小程序 一键授权 给第三方平台代开发管理(二,一键授权给第三方平台)
热门文章
- HTML基础-第二讲
- java.net.URISyntaxException的解决办法
- Linux Mint 18.2 Sonya 将于 6 月上旬发布公测版本
- 使用DocFX生成文档
- 关于“如何破坏单例“我说了好几种方式,面试官却说:我其实随便问问,没想到你真会
- 厉害了,12306 是如何顶住一秒百万流量的?
- Consul入门05 - 健康检测
- SpringBoot常用配置简介
- 网络:http请求之几种常见技术
- Android --- BaseQuickAdapter 子控件设置了addOnClickListener(R.id.xxx);点击的时候还是没反应