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,常用以下两种配置方法
方法一:配置文件指定扫描路径(推荐)
mybatis:
mapper-locations: classpath:mapping/*.xml #注意:一定要对应mapper映射xml文件的所在路径
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里面
BindingException: Invalid bound statement (not found)问题排查:SpringBoot集成Mybatis重点分析的更多相关文章
- 配置文件出错 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): <!-- mybatis 配置- ...
- Spring boot结合mybatis开发的报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),经过排查确定是没有找到xml的原因 ...
- 【踩坑】遇到 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 报错
今天在重做 iblog 客户端时,测试接口情况,发现了 org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...
- springboot项目下的Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
今天遇到mybatis-puls的报错Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (n ...
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): da.huying.usermanag ...
- Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
主要错误信息如下: HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...
- mybatis使用时org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的错误
最近在使用mybatis时,出现了 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 这 ...
- IDEA异常解决: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
有时候解决问题不仅仅是解决问题.-----jstarseven 最近因为开发需要,需要搭建一个ssm开发框架,采用了开发工具IDEA. 整合完了SSM开发框架之后,发布的时候出现org.apache. ...
- MyBatis绑定错误--BindingException:Invalid bound statement (not found)
如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...
随机推荐
- SZU2
CF:Problem 425A 区间暴力,枚举区间.交换选定区间最小值和剩余区间最大值k次. 其实等同于将剩余区间最大k个加到选定区间里,然后排序 #include <iostream> ...
- SQL SERVER 2012修改数据库名称(包括 db.mdf 名称的修改)
假设原来数据库名为db,附加数据库为db.mdf和db_log.ldf.需要改成dbt,及dbt.mdf和dbt_log.ldf. 步骤: .首先把原来的数据库进行备份(选择数据库->右键-&g ...
- Python入门-初始函数
今天让我们来初步认识一个在python中非常重要的组成部分:函数 首先,让我们来幻想这样一个场景: 比如说我们现在想要通过社交软件约一个妹子,步骤都有什么? print('打开手机 ') print( ...
- 软件项目技术点(1)——Tween算法及缓动效果
AxeSlide软件项目梳理 canvas绘图系列知识点整理 Tween算法及缓动效果 软件里在切换步序时需要有过渡动画效果,从当前位置的画面缓动到目标位置的画面.动画效果可重新查看文章系列第一篇 ...
- ES6学习笔记(一)
‘变量’声明 ES6新增两个声明’变量’的关键字,let和const命令. l let用来声明局部变量 同ES5中var声明的变量不同的是,let声明的变量的作用域范围仅仅是从其声明的地方开始,到其 ...
- Linux ->> UBuntu 14.04 LTE下设置静态IP地址
UBuntu 14.04 LTE设置IP地址和一些服务器版本的Linux还不太一样.以Centos 7.0为例,网卡IP地址的配置文件应该是/etc/sysconfig/network-scripts ...
- Linux ->> Ubuntu 14.04 LTE下配置SSH免密码登录
首先用apt-get命令安装SSH jerry@ubuntu:~$ sudo apt-get install ssh [sudo] password for jerry: Reading packag ...
- Service Discovery in WCF 4.0 – Part 2 z
Service Discovery in WCF 4.0 – Part 2 In the previous post I discussed about the basic usage of WCF ...
- Java字符串工具类
import java.io.ByteArrayOutputStream;import java.io.UnsupportedEncodingException;import java.lang.re ...
- selenium+python 数据驱动-csv篇,可封装
#循环读取csv文件中的数据,可以作为用户名,密码等使用from selenium import webdriverimport csv#获取csv文件中password列with open(r'C: ...