特殊情况
父类导错包
//@NotNull父类原本需要导入import javax.validation.constraints.NotNull;却导入了import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.NotNull;//错误的包
import lombok.Data;
@Data
public class QualityTestingStandardEntity{
@NotNull
private Integer baseScore;
}
导致子类使用@Data主键报错:Lombok needs a default constructor in the base class
import lombok.Data;
@Data//因为父类导错包,此时子类会报:Lombok needs a default constructor in the base class
public class QualityTestingStandardEntityDto extends QualityTestingStandardEntity{
}
正确导包
父类
import lombok.Data;
import javax.validation.constraints.NotNull;//正确的包
@Data
public class QualityTestingStandardEntity{
@NotNull
private Integer baseScore;
}
子类使用@Data会提示需要使用@EqualsAndHashCode(callSuper=false)
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper=false)
public class QualityTestingStandardEntityDto extends QualityTestingStandardEntity{
}
包太旧lombok版本<=1.16.22,需要升级版本
pom.xml升级到指定版本
lombok官方建议maven配置和spring boot推荐配置
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<!--打包时排除lombok依赖,因为lombok只在编译阶段使用-->
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
build.gradle升级到指定版本
lombok官方建议gradle配置
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'