一直在使用MapStruct版本1.3.3.Final并且没有出现问题。 更改为版本 1.5.5 后。最终事情开始崩溃。 检查“mvn clean install”后生成的实现文件,发现并非所有属性都被继承,无法找出原因或任何模式。
下面是所使用内容的简化示例。 实际的设置有多层继承。 感谢这里的一些线索和指导。
@Mappings({
@Mapping(source = "incomingPayment.currency" target = "currency"
@Mapping(source = "incomingPayment.debtorAccount" target = "debtorAccount"
@Mapping(source = "incomingPayment.debtorAlias" target = "debtorAlias"
})
Payment mapIncomingPayment(IncomingPayment incomingPayment);
@InheritConfiguration(name = "mapIncomingPayment")
@Mappings({
@Mapping(source = "incomingPayment.amt" target = "amt")
})
Payment mapIncomingUSDPayment(IncomingPayment incomingPayment);
您可以在 pom.xml 文件的构建部分尝试此配置吗?
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</dependency>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>