MapStruct 创建实例 Mappers.getMapper() 报错: Cannot find implementation for com.ruoyi.api.convert.DataConvert

2024-07-12T11:11:10

环境

若依 v3.8.8
MapStruct v1.5.5.Final

报错代码

@Mapper
public interface DataConvert {

    DataConvert INSTANCE = Mappers.getMapper(DataConvert.class); // 报错位置

    @Mappings({
            @Mapping(source = "imei", target = "deviceCode"),
            @Mapping(source = "ACC", target = "accStatus"),
    })
    BizDevice deviceYunGuTobizDevice(DeviceYunGu deviceYunGu);

    List<BizDevice> convert(List<DeviceYunGu> deviceYunGuList);
}

运行时报错:java.lang.ClassNotFoundException: Cannot find implementation for com.ruoyi.api.convert.DataConvert

解决

@Mapper 注解路径使用错误,应该引入的是 org.mapstruct.Mapper,错误引入了 org.apache.ibatis.annotations.Mapper

修正之后,再报错:Can't map property "long signalTime" to "Date signalTime". Consider to declare/implement a mapping method: "Date map(long value)".

这是 MapStruct 构建的时候报错的,这说明定义的 DataConvert 实例有被正确引入,之后再去解决这个映射属性类型不一致的问题就好。

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »