mybatis plus3.1.0 热加载mapper
今天又开始写业务代码了,每次修改SQL都要重启服务,实在是浪费时间。
想起之前研究过的《mybatis plus3.1.0 热加载mapper》,一直没有成功,今天静下心来分析了问题,终于找到原因了。
上文中提到的MybatisPlusConfig,断点分析到获取资源文件未0个,不对劲。
resources = resourceResolver.getResources(mapperLocations)
于是我发现我的本地配置可能不是很好。改了一下:
mybatis-plus:
mapper-locations: classpath:/mybatis/mapper/*-mapper.xml,/mybatis/mapper/*/*Mapping.xml
改为如下
mybatis-plus:
mapper-locations: classpath*:mybatis/mapper/*/*.xml
后面加载到资源文件了,可是又遇到了另外的坑,文章中的MybatisMapperRefresh类,明明定义了集合类型,可还是有其他类型的对象在,然后就报类型转换的错误。我想到了用迭代来做转换,终于成功了。
Collection<MappedStatement> mappedStatements = configuration.getMappedStatements();
这里居然存在org.apache.ibatis.session.Configuration$StrictMap$Ambiguity,然后转换到MappedStatement对象就报类型转换的错误了。用下框红字的办法解决了。
private void cleanKeyGenerators(List<XNode> list, String namespace) {
for (XNode context : list) {
String id = context.getStringAttribute("id");
configuration.getKeyGeneratorNames().remove(id + SelectKeyGenerator.SELECT_KEY_SUFFIX);
configuration.getKeyGeneratorNames().remove(namespace + "." + id + SelectKeyGenerator.SELECT_KEY_SUFFIX);
Collection<MappedStatement> mappedStatements = configuration.getMappedStatements();
List<MappedStatement> objects = Lists.newArrayList();
Iterator<MappedStatement> it = mappedStatements.iterator();
while (it.hasNext()){
Object object=it.next();
if(object instanceof org.apache.ibatis.mapping.MappedStatement) {
MappedStatement mappedStatement=(MappedStatement)object;
if (mappedStatement.getId().equals(namespace + "." + id)) {
objects.add(mappedStatement);
}
}
}
// for (MappedStatement mappedStatement : mappedStatements) {
// if (mappedStatement.getId().equals(namespace + "." + id)) {
// objects.add(mappedStatement);
// }
// }
mappedStatements.removeAll(objects);
}
}
然后这样起作用了。
之前还研究了一篇文章,说是用idea插件模式进行,不过启动了之后,报错了,于是也没有深入。还是用代码方式好一点。
不过倒是get了很多新姿势。
https://githuboy.online/2019/05/11/基于JRebel开发的MybatisPlus热加载插件/
mybatis plus3.1.0 热加载mapper的更多相关文章
- Mybatis热加载Mapper.xml
开发的时候,写Mybatis Mapper.xml文件的时候,每次修改SQL都需要重启服务,感觉十分麻烦,于是尝试写了一个Mybatis的Mapper.xml热加载. 能在修改Mapper.xml之后 ...
- mybatis热加载的实现
最近在使用mybatis,由于是刚刚开始用,用的并不顺手,目前是感觉有2个地方非常的不好用: 1.mybatis调试不方便 由于dao层只有接口,实现只是一个map的xml文件,想加断点都没有地方加, ...
- (转)mybatis热加载(依赖mybatis-plus插件)的实现
最近在使用mybatis,由于是刚刚开始用,用的并不顺手,目前是感觉有2个地方非常的不好用: 1.mybatis调试不方便 由于dao层只有接口,实现只是一个map的xml文件,想加断点都没有地方加, ...
- DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描
DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载 吐槽之后应该有所改了,该方式可以作为一种过渡方式 ...
- DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描
DB数据源之SpringBoot+MyBatis踏坑过程(三)手工+半自动注解配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许禁止转载 系列目录连接 DB数据源之Spr ...
- 在mybatis 中批量加载mapper.xml
可以直接加载一个包文件名,将这个包里的所有*mapper.xml文件加载进来. 指定mapper接口的包名,mybatis自动扫描包下边所有mapper接口进行加载: 必须按一定的标准:即xml文件和 ...
- 抛开 Spring ,你知道 MyBatis 加载 Mapper 的底层原理吗?
原文链接:抛开 Spring ,你知道 MyBatis 加载 Mapper 的底层原理吗? 大家都知道,利用 Spring 整合 MyBatis,我们可以直接利用 @MapperScan 注解或者 @ ...
- 精尽MyBatis源码分析 - MyBatis初始化(二)之加载Mapper接口与XML映射文件
该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...
- Mybatis源码解读-配置加载和Mapper的生成
问题 Mybatis四大对象的创建顺序? Mybatis插件的执行顺序? 工程创建 环境:Mybatis(3.5.9) mybatis-demo,参考官方文档 简单示例 这里只放出main方法的示例, ...
随机推荐
- 电脑上做的ppt拿到别的电脑或手机上播放的时候字体错位的解决方法
原因:字体不对!!! 比如你英文用的Calibri字体,但是手机的wps或者别的电脑上的低版本的office没有这个字体,所以就会强制转换成那里有的字体(一般是黑体),此时字体就会错位!! 不要以为那 ...
- JQuery--jQquery控制CSS样式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Markdown Linux
如何在Linux下使用Markdown进行文档工作 学习于: http://www.ituring.com.cn/article/10044 Markdown 官网: http://daringfir ...
- windows下 python中报错ImportError: No module named 'requests'
原因没有安装requests模块, 可以切换到python的安装目录找到 script文件夹 example: 进入cmd窗口切换到上面的目录直接运营下面两个命令中的一个 1. > Path\p ...
- springboot(十九)使用actuator监控应用【转】【补】
springboot(十九)使用actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的 ...
- jQuery圆盘抽奖
在线演示 本地下载
- 安装LoadRunner11时,缺少vc2005_sp1_with_atl_fix_redist错误的解决方案
安装LoadRunner11时,会报缺少vc2005_sp1_with_atl_fix_redist错误,类似下图所示: 由提示信息可知,这里是由于本机缺少该组件所致,解决方案就是安装此组件,可以去网 ...
- ios开发使用Basic Auth 认证方式
http://blog.csdn.net/joonchen111/article/details/48447813 我们app的开发通常有2种认证方式 一种是Basic Auth,一种是OAuth ...
- bzoj1221 软件开发
Description 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员 ...
- jQuery,javascript获得网页的高度和宽度$(document).height / $(window).height
一.javascript 网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeight 网页可见区域宽: documen ...