SpringBoot——单元测试error: can not execute. because can not find cache of TableInfo for entity!
问题
单元测试时,遇到以下报错:
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: error: can not execute. because can not find cache of TableInfo for entity!
at com.baomidou.mybatisplus.core.toolkit.ExceptionUtils.mpe(ExceptionUtils.java:49)
at com.baomidou.mybatisplus.core.toolkit.Assert.isTrue(Assert.java:38)
at com.baomidou.mybatisplus.core.toolkit.Assert.notNull(Assert.java:72)
at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.saveOrUpdateBatch(ServiceImpl.java:174)
at com.baomidou.mybatisplus.extension.service.IService.saveOrUpdateBatch(IService.java:91)
... ....
解决方案
在测试类中,添加mybatis的初始化构建
/**
* before设置
*/
@Before
public void setUp() {
//构建mybatis
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), UserEntity.class);
}
烧不死的鸟就是凤凰
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
2022-01-05 IDEA——修改idea64.exe.vmoptions文件解决coding卡顿问题