I am trying to develop a web application with SpringBoot
and Lombok
to reduce boilerplate code.
While the annotated class works fine, I am getting compilation errors in target classes.
I am not trying to compile via IDE but directly via commandline using gradlew build.
Any suggestion on how to integrate Lombok
with gradle
to build and generate jars will be really helpful.
Git repository: https://github.com/ashubisht/sample-sbs.git
The error I am getting is:
\sample-sbs\src\main\java\com\sample\springboot\Controllers\RestControllerClass.java:28: error: constructor Customer in class Customer cannot be applied to given types; customerDAO.insert(new Customer(1, "Utkarsh", 25)); ^ required: no arguments found: int,String,int reason: actual and formal argument lists differ in length 1 error
Customer class is annotated with @Data annotation.
In your Customer
class, all the fields that you're trying to initialize in the constructor are non-final.
Since @Data
annotation adds only @RequiredArgsConstructor
, you cannot initialize non-final fields in the constructor without explicitly annotating this class with @AllArgsConstructor
.
So you either need to annotate the class with @AllArgsConstructor
, or use setters to initialize the object.