heisenberg
heisenberg

Reputation: 1954

Sub class of Parent class using @RequiredArgsConstructor Lombok is not finding default constructor in Parent class

I'm working on a Spring project with Lombok plugin. I added @RequiredArgsConstructor annotation and made the parent class's fields final to initialize it using either @AllArgsConstructor or @RequiredArgsConstructor instead of field injection (using @Autowired for class fields). However, for some reason, the subclass DraftsPostMethod is reporting a message that there's no default constructor found in the parent class AbstractContributoryServiceMethod

I'm not sure what's causing it because I did the same (added the annotation) on other classes to initialize them Lombok way.

The subclass reports an error that reads "There is no default constructor available in ... AbstractContributoryServiceMethod"

Subclass:

@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...
}

Parent class :

@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...
}

I'd appreciate any comments or answers. Thank you.

Upvotes: 1

Views: 9425

Answers (1)

John_IV
John_IV

Reputation: 1

Lombok's @NoArgsConstructor annotation will generate the default constructor it is looking for.

https://projectlombok.org/features/constructor

Upvotes: 0

Related Questions