Mapstruct不会在生成的源文件中更新其getter和setter方法 [英] Mapstruct is not updating its getters and setters in the generated source files
问题描述
我有一个实体,该实体具有我以前这样写的属性 私人Long ICU;
I have an entity with a property I used to write like this private Long ICU;
我正在使用mapstruct:
I'm using mapstruct:
这是该实体的我的映射器:
Here is my mapper for said entity:
@Mapper(componentModel = "spring")
public interface ProtectionQueryMapper extends EntityMapper<ProtectionQueryDto, Protection> {
ProtectionQueryDto toDto(Protection protection);
Protection toEntity(ProtectionQueryDto protectionQueryDto);
List<Protection> toEntity(List<ProtectionQueryDto> protectionQueryDtos);
List<ProtectionQueryDto> toDto(List<Protection> protections);
}
public interface EntityMapper<D, E> {
E toEntity(D dto);
D toDto(E entity);
List<E> toEntity(List<D> dtoList);
List<D> toDto(List<E> entityList);
}
我遇到的问题是我想从ICU go icu更改属性,这导致了此错误:
The problem I have is that I want to change the property from ICU go icu, which I did and it resulted in this error:
嵌套的异常是java.lang.NoSuchMethodError:
nested exception is java.lang.NoSuchMethodError:
Protection.getICU()Ljava/lang/Long;
Protection.getICU()Ljava/lang/Long;
似乎mapstruct根据以下内容生成了它的getter和setter:
private Long ICU;
setICU和getICU之类的生成方法.
但是,现在我已将属性从ICU更改为icu mapstruct,现在没有将其方法更新为setIcu
和getIcu
.
It would seem that mapstruct generated its getters and setters based on:
private Long ICU;
generating method like setICU and getICU.
But now that I have changed the property from ICU to icu mapstruct is not updating its method to setIcu
and getIcu
.
我无法手动更改mapstruct
生成的文件.
I cannot change the mapstruct
generated file manually.
这也是我的pom.xml(至少是有关mapstruct的部分)
Also here is my pom.xml (at least the part regarding mapstruct)
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.3.0.Final</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
<arg>-Amapstruct.defaultComponentModel=spring</arg>
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
有什么想法要让mapstruct更新其生成的源文件吗?
Any idea how to have mapstruct update its generated source file?
推荐答案
由于某种原因,项目的重新编译未运行注释处理器. Java编译器将调用MapStruct,而maven-compiler-plugin负责使用生成的类清理文件夹.
For some reason the recompile of the project didn't run the annotation processor. MapStruct is invoked by the Java compiler and the maven-compiler-plugin is responsible for cleaning up the folder with the generated classes.
执行mvn clean compile
将始终有效.但是,如果没有做任何更改然后再做mvn compile
,我将尝试使用最新版本的maven-compiler-plugin,如果仍然无法正常工作,则为该插件创建一个错误报告.
Doing mvn clean compile
will always work. However, if doing a change and then doing mvn compile
doesn't, I would try with the latest version of the maven-compiler-plugin and if that still doesn't work create a bug report for the plugin.
这篇关于Mapstruct不会在生成的源文件中更新其getter和setter方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!