Reputation: 291
I have used @Data
annotation in my POJO Class but the getters and setters are not generated.
IDE which I am using is sts(Spring Tool Suite)
//User POJO Class
import lombok.Data;
@Data
public class UserVo {
private String name;
private String userName;
private String email;
private String mobile;
private String password;
}
<!-- pom.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aptitest</groupId>
<artifactId>wt-online-test-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>wt-online-test-backend</name>
<description>Online Aptitude Test</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Upvotes: 23
Views: 105655
Reputation: 1
Lombok used to generate getter setter and constructor automatically for you ,Well described here. https://www.youtube.com/watch?v=PfokdlpwyjQ
Upvotes: 0
Reputation: 1
To install Lombok in Eclipse and its variants (like Spring Tool Suite) via the Eclipse plugin installer, you can follow these steps:
Open your IDE and navigate to Help
> Install New Software...
In the "Work with" field, enter https://projectlombok.org/p2 and check the box next to "Lombok":
Complete the installation process and then quit your IDE and start it again (a regular restart may not be sufficient).
Upvotes: 0
Reputation: 36
It is obvious that the problem is project Lombok not working properly. I have the same issue. It perfectly works on IntelliJ, and my instructor told me that IntelliJ has additional plugins that will automatically be installed but vs code and like don't have that feature, so you need manually install project Lombok.so, try by installing the vs code extension related to Lombok.
Upvotes: 0
Reputation: 41
You need to install a lombok jar and add it to build path for eclipse user.
https://howtodoinjava.com/automation/lombok-eclipse-installation-examples/#lombok-eclipse
Alternatively, you can generate getters and setters from source in eclipse and ditch the @Data annotation
Upvotes: 0
Reputation: 61
Follow these steps: (100% working)
[https://projectlombok.org/download][1]
]Eg:
import lombok.Data;
import lombok.NonNull;
public @Data class Project {
@Id
private @NonNull String id;
private @NonNull String name;
private @NonNull String description;
}
Upvotes: 0
Reputation: 21
You need to add @Setter
& @Getter
annotations to the class, when using Lombok within your pom.xml
alternatively use @Data
which includes both
Upvotes: -5
Reputation: 11
As you are using spring boot, you can omit the version of lombok (which will then be inherited from the Spring Boot parent POM). Also check that your your IDE is well configured !
2. Setting up Lombok with Eclipse and Intellij
Upvotes: 0
Reputation: 111
For Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
For Gradle:
developmentOnly 'org.springframework.boot:spring-boot-devtools'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Upvotes: 10
Reputation: 305
1.Download Lombok Jar File
Add below dependency in your maven project so that it got downloaded first in your local repository.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
Now do a mvn clean install command on the newly created project to get this jar downloaded in the local repository.
2.Start Lombok Installation
Once the jar downloaded in Local repository, goto the jar location from command prompt and run the following command java -jar lombok-1.16.18.jar and we should be greeted by Lombok installation window provided by lombok.
Now click on the “Specify Location” button and locate the eclipse.exe path under eclipse installation folder like this.
Now click the “Install/Update” button and we should finish installing Lombok in eclipse.
After all the setup done properly you can use all the provide jar of Lombok.
Like:
For more details :
Upvotes: 2
Reputation: 13572
Lombok is an annotation processor - it has full access to the generated source tree. While annotation processors usually generate new source files, Lombok modifies existing ones by adding new fields or methods.
There are a lot of annotations provided by Lombok. (See full List)
To answer the question: Lombok annotations do not generate the code in development time. It happens only when the Java compiler generates an Abstract Source Tree. So don't expect the code to magically change whenever you add an annotation.
But,you need to get them resolved in your specific IDE so that all dependencies and imports are correctly added. Given below are the ways to resolve Lombok annotations in your preferred IDE. You can also go for a Maven project and resolve these as well (Project Lombok Maven repository).
IntelliJ Idea
1) Enable Annotation Processing
File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> (Tick the checkbox as per the image given below)
2) Install/Update Lombok Plugin (see this)
File -> Settings -> Plugins -> Search for Lombok Plugin -> Update or Install
Eclipse
Follow these steps in this link.
Upvotes: 6
Reputation: 5316
In my case the generated class had lombok generated getters / setters on my entity class. But I was still getting null values being bound for all fields in my entity except for @Id field. I am using gradle not maven.
What fixed the problem for me was to install the Lombok plugin in IntelliJ CE IDE and also to enable the annotation processing for the IDE / project.
After that I am able to persist my entity just fine!
Upvotes: 0
Reputation: 10515
The problem here is likely related to your ability to check if getters/setters were actually generated.
If your IDE tells you getters/setters not generated - the IDE might be wrong. It may not pick that getters/setters were generated; For your IDE - make sure you have relevant plugins for that. This is most likely your issue as you are mentioning STS. Try one of links relevant to your case:
Use IDE-independent Maven build to make sure that Lombok generates what it is supposed to.
Upvotes: 10
Reputation: 47
The Spring Tool Suite IDE is based on eclipse.
From the official Lombok documentation : https://projectlombok.org/download.html
Eclipse and variants — Run lombok.jar as a java app (i.e. doubleclick it, usually) to install. Also add lombok.jar to your project. Supported variants: Springsource Tool Suite, JBoss Developer Studio
If it still does not work, this Stack Overflow discussion might help you :
how to configure lombok in eclipse luna
Upvotes: 1
Reputation: 11
Study this sample project with Springboot + Lombok. This class use @Data: https://github.com/raulvillalbamedina/exampleApiHateoas/blob/master/src/main/java/com/rvillalba/exampleApiHateoas/entity/Example.java
If your IDE has errors, you need a plugin: "Eclipse and variants Run lombok.jar as a java app (i.e. doubleclick it, usually) to install. Also add lombok.jar to your project. Supported variants: Springsource Tool Suite, JBoss Developer Studio IDEA IntelliJ A plugin developed by Michael Plushnikov adds support for most features."
Upvotes: -1
Reputation: 27078
Firstly, you don't need to add @Setter and @Getter. @Data includes these two.
Secondly, you need to add lombok plugin to your IDE.(search for lombok plugin for STS or Enabling Annotation processor for STS). When you do so, you don't really see getters and setters generated in your IDE. This will help in you getting through with compile time errors in your IDE. thats all.
Upvotes: 1
Reputation: 2555
You also have to add lombok aus an agent to your IDE. See https://projectlombok.org/download.html for details.
Upvotes: 0