问题

如果你的项目中同时使用了Lombok、MapStruct,项目启动时报错:Unknown property "xxx" in result type Class. Did you mean "null"?

原因

MapStruct 在编译期看不到 Lombok 生成的 getter / setter,所以运行项目时会认为具体的类里没有 对应的字段 属性,

解决

pom 文件中加一个桥接依赖:

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

同时 pom 文件中增加配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.11.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <annotationProcessorPaths>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-mapstruct-binding</artifactId>
                <version>0.2.0</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐