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);
    }
posted @   Andya_net  阅读(705)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-01-05 IDEA——修改idea64.exe.vmoptions文件解决coding卡顿问题
点击右上角即可分享
微信分享提示