mapstruct常见错误及解决方案

1 问题集合

  • mapstruct-jdk8 编译报错

我以前项目使用的是mapstruct-jdk8<=1.3.1.Final ,现在做改造升级,比如springboot升级等,但是报错了

我们去mvn仓库去看下:

  • Deprecated MapStruct artifact containing annotations to be used with JDK 8 and later - Relocated to mapstruct
  • 具体看1.3.1.Final版本,如图所示:在这里插入图片描述

项目过时了,虽然mapstruct-jdk8>=1.4.0.Final版本仍然可以使用,但是建议用mapstruct代替。

  • Cannot find implementation

首先检查是否添加依赖支持,如下:

<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct</artifactId>
    <version>${mapstruct.version}</version>
</dependency>
<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-processor</artifactId>
    <version>${mapstruct.version}</version>
</dependency>
  • Couldn’t retrieve @Mapper annotation

如果项目中同时使用了swagger注解,可能是依赖冲突导致的,解决如下:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${swagger2.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  • Cannot find implementation

我依赖也加了,也屏蔽了冲突依赖,但是还是报错Cannot find implementation,啥情况?

在使用了该注解的模块执行mvn clean install,此时就生成了@Mapper注解的接口的默认实现类,图示在这里插入图片描述

2 后记

小伙伴如在项目中遇到mapstruct其他相关问题,欢迎交流或者留言

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gaog2zh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值