Mapstruct使用时报Unknown property xxx in result type xxx. Did you mean null

0.背景

使用mapstruct时出现:

Unknown property "xxx" in result type xxx. Did you mean "null"?

同时,项目中也用到了lombok。

mapstruct版本: 1.4.1.Final

lombok版本: 1.8.22 (继承的Spring2.5.6)

<!-- mapstruct START--> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct</artifactId> <version>${mapstruct.version}</version> <!--这个scope 只能作用在编译和测试时,同时没有传递性。--> <scope>provided</scope> </dependency> <dependency> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> <scope>provided</scope> </dependency> <!-- mapstruct END --> <!-- lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency>

1.解决

1.1 方案1:调整顺序

代码生成器annotationProcessor标签部分,将lombok放在mapstruct之前

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <!--自动生成代码annotationProcessor--> <annotationProcessorPaths> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>${mapstruct.version}</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build>

1.2 方案2:官网叽叽歪歪一堆

官网说Lombok 1.18.16或更高版本要添加lombok-mapstruct-binding的依赖,但是经过方案1我的问题它就解决了

原文在这里:https://mapstruct.org/faq/

其实文中也提到了先在模块1使用lombok再在模块2使用mapstruct。

image-20220121002958457

        <!-- mapStruct-lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-mapstruct-binding</artifactId>
            <version>0.2.0</version>
            <scope>provided</scope>
        </dependency>

 


 

posted @   牧之丨  阅读(1091)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-03-15 Base64解码、Base64编码、Base64加密解密规则
2022-03-15 SpringBoot项目请求路径中有正反斜杠的处理办法
点击右上角即可分享
微信分享提示