skip to Main Content

I am working on a Spring Boot project in IntelliJ IDEA and encountered the following error when trying to create an instance of a class and call its getter method:
Check image to get idea what was my question & error

Error:
java: constructor User in class com.example.HealthCare.User cannot be applied to given types;
required: no arguments
found: java.lang.String
reason: actual and formal argument lists differ in length

I am using Lombok annotations (@Data, @NoArgsConstructor, and @AllArgsConstructor) in my User class to automatically generate constructors and getter/setter methods. Here’s the relevant code:

User.java

package com.example.HealthCare;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
    private String name;
}

HealtCareApplication.java


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HealthCareApplication {
    public static void main(String[] args) {
        SpringApplication.run(HealthCareApplication.class, args);

        User user = new User("Shubham");
        System.out.println(user.getName());
    }
}

Steps I have tried:

Verified that annotation processing is enabled in IntelliJ IDEA.
Checked the Lombok plugin version, Spring Boot version, and my system (Ubuntu). All are properly set up and up-to-date.
Cleaned and rebuilt the project multiple times.
When I clone a working project from another source, the same setup works. However, when I create a new project from scratch with similar configurations, this issue occurs.

My Environment:

OS: Ubuntu 24.04
Spring Boot Version: 3.4.0
Lombok Version: 1.18.30
IDE: IntelliJ IDEA 2024.3.1

Why does Lombok not generate constructors and getter methods in my project, despite everything being correctly configured? Could there be a configuration or setup issue specific to a newly created project?

2

Answers


  1. Check your version of Lombok, and ensure that the plugin configuration in the pom.xml file remains unchanged. Sometimes invalidating caches in IntelliJ is ineffective.

    Login or Signup to reply.
  2. The issue might be related to your project dependencies or how Lombok is configured. To ensure your project is set up correctly, try replacing your pom.xml file with the content provided in this gist.

    This updated pom.xml includes proper Lombok configurations and other necessary dependencies that might resolve the problem. After updating the file, follow these steps:

    1. Reload Maven Project:

      • In your IDE (e.g., IntelliJ IDEA or Eclipse), right-click the project and select Maven > Reload Project.
    2. Enable Annotation Processing:

      • Ensure that annotation processing is enabled in your IDE settings.
        • IntelliJ IDEA: Go to File > Settings > Build, Execution, Deployment > Compiler > Annotation Processors and check "Enable annotation processing."
        • Eclipse: Annotation processing is usually enabled by default, but double-check under Project Properties > Java Compiler > Annotation Processing.
    3. Rebuild the Project:

      • Clean and rebuild your project to ensure all annotations are processed correctly.
    4. Verify Lombok Setup:

      • Confirm Lombok is installed in your IDE. For IntelliJ IDEA, install the Lombok plugin from the plugin marketplace.

    If the problem persists, check for any conflicting dependencies or versions in your pom.xml. Also, ensure the class you’re trying to use Lombok annotations in is compiled without errors.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search