mybatis-flex / mybatis-flex

mybatis-flex is an elegant Mybatis Enhancement Framework
https://mybatis-flex.com
Apache License 2.0
1.89k stars 182 forks source link

SpringBoot web环境添加mybatis-flex-processor依赖报错 #170

Closed toint-cn closed 1 year ago

toint-cn commented 1 year ago

依赖如下

<!--mybatis-flex-processor-->
<dependency>
    <groupId>com.mybatis-flex</groupId>
    <artifactId>mybatis-flex-processor</artifactId>
</dependency>

报错如下

Caused by: java.lang.ClassCastException: class cn.toint.core.pojo.DO.WechatMpConfigDO cannot be cast to class cn.toint.core.pojo.DO.WechatMpConfigDO (cn.toint.core.pojo.DO.WechatMpConfigDO is in unnamed module of loader 'app'; cn.toint.core.pojo.DO.WechatMpConfigDO is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @44c1c769)

业务代码

// 根据给定的appid查找配置
        WechatMpConfigDO wechatMpConfigDO;
        try {
            wechatMpConfigDO = this.wechatMpConfigService.getOne(
                    QueryWrapper.create().where(WechatMpConfigDO::getAppid).eq(appId));
        } catch (Exception e) {
            throw new DbException("查询appid失败", e);
        }

SpringBoot版本:2.7.15

解决:去掉mybatis-flex-processor就不报错了。

toint-cn commented 1 year ago

看到官网文档对于这个依赖的描述「提供APT服务」,但是这个报错的背景没有配置APT服务的,也没有将依赖设置为:

 <scope>provided</scope>

会是这次报错的原因么。

添加2个信息:

  1. 单元测试不会报错,启动web服务后http调用就报错。
  2. 是个Maven聚合项目,依赖传递一共有三层,依赖声明在最底层,调用在第二层,第三层是打包层。
yangfuhai commented 1 year ago

参考文档:https://mybatis-flex.com/zh/faq.html#springboot-%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%87%BA%E7%8E%B0-class-com-xxx-cannot-be-cast-class-com-xxx-%E7%9A%84%E9%94%99%E8%AF%AF