使用 @RequiredArgsConstructor Lombok 的父类的子类未在父类中找到默认构造函数

问题描述 投票:0回答:1

我正在使用 Lombok 插件开发一个 Spring 项目。我添加了

@RequiredArgsConstructor
注释,并使用
final
@AllArgsConstructor
来初始化父类的字段
@RequiredArgsConstructor
,而不是字段注入(对类字段使用
@Autowired
)。 但是,由于某种原因,子类 DraftsPostMethod 报告一条消息:在父类 AbstractContributoryServiceMethod 中找不到默认构造函数

我不确定是什么原因导致的,因为我在其他类上做了同样的事情(添加了注释)以 Lombok 方式初始化它们。

子类报告错误,内容为“

... AbstractContributoryServiceMethod中没有可用的默认构造函数”

子类:

@Service public class DraftsPostMethod extends AbstractContributoryServiceMethod<DraftManagementRequest, BasicServiceModel<DraftManagementRequest>, BasicServiceResponse<Void>> { private final Validator<DraftManagementRequest> validator = new Validator<DraftManagementRequest>(){ @Nonnull @Override public ValidationState validate(DraftManagementRequest draftManagementRequest){ return ValidationState.commence(); } }; private final DraftService draftService; @Autowired public DraftsPostMethod(DraftService draftService){ // getting the red line error here this.draftService = draftService; } //...and so on... }

家长班:

@RequiredArgsConstructor public abstract class AbstractContributoryServiceMethod { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); private final ExceptionManager exceptionManager; //this line was @Autowired private ExceptionManager exceptionManager private final ValidationErrorTranslator validationErrirTranslator; //this line was @Autowired private ValidationErrorTranslator validationErrirTranslator private final ExceptionDetailsLogger exceptionDetailsLogger; //this line was @Autowired private ExceptionDetailsLogger exceptionDetailsLogger //... and so on... }
如有任何意见或答案,我将不胜感激。谢谢。

java spring-mvc lombok intellij-lombok-plugin
1个回答
0
投票
Lombok 的 @NoArgsConstructor 注释将生成它正在寻找的默认构造函数。

https://projectlombok.org/features/constructor

© www.soinside.com 2019 - 2024. All rights reserved.