How to use lombok. This annotation in Spring application to download?

I used the @Data annotation in my POJO class, but the receivers and setters are not generated. The IDE I use 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> 
+12
java spring-boot
source share
9 answers

The problem here is probably related to your ability to check if getters / setters were actually received.

  1. If your IDE reports that getter / setters are not generated, the IDE may be incorrect. This may not determine that getters / setters were received; For your IDE - make sure you have the appropriate plugins for this. This is most likely your problem since you mention STS. Try one of the links relevant to your case:

  2. Use the IDE-independent Maven build to make sure Lombok generates what it should.

+5
source share
 <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> 
+4
source share

First, you do not need to add @Setter and @Getter. @ Date includes these two.
Secondly, you need to add the lombok plugin to your IDE (search for the lombok plugin for STS or Enabling Annotation processor for STS). When you do this, you don’t see how getters and setters are generated in your IDE. This will help you overcome compile-time errors in your IDE. all this.

+1
source share

You also need to add the lombok aus agent to your IDE. See https://projectlombok.org/download.html for more details.

0
source share

The Spring Tool Suite IDE is based on eclipse.

From the official Lombok documentation: https://projectlombok.org/download.html

Eclipse and options. Run lombok.jar as a Java application (for example, double-click it, as a rule) to install. Also add lombok.jar to your project. Supported Options: Springsource Tool Suite, JBoss Developer Studio

If this still does not work, this discussion may help you:

how to set up lombok in eclipse luna

0
source share

In my case, the generated / set methods for my entity class were generated in the generated lombok class. But I was still getting null values ​​bound to all fields in my entity except the @Id field. I use Gradle, not Maven.

What solved the problem for me was to install the Lombok plugin in IntelliJ CE IDE, as well as enable annotation processing for the IDE / project.

After that, I can keep my essence just fine!

0
source share

Lombok is an annotation processor - it has full access to the generated source tree. While annotation processors typically generate new source files, Lombok modifies existing ones by adding new fields or methods.

There are many annotations provided by Lombok. (See Complete List )

To answer the question: Lombok annotations do not generate code at design time. This only happens when the Java compiler generates an abstract source tree. Therefore, do not expect the code to magically change whenever you add an annotation.

But you need to enable them in your specific IDE so that all dependencies and imports are added correctly. The following are ways to resolve Lombok annotations in your IDE. You can also go to the Maven project and enable them ( Project Lombok Maven repository ).

IntelliJ Idea

1) Enable annotation processing

File β†’ Settings β†’ Build, Execution, Deployment β†’ Compiler β†’ Annotation Processors β†’ (Check the box as shown below)

Enable Annotation Processor

2) Install / update the Lombok plugin ( see This )

File β†’ Settings β†’ Plugins β†’ Search Lombok plugin β†’ Update or install

Eclipse

Follow these steps in this link .

0
source share

Explore this sample project with Springboot + Lombok. This class uses @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 options Run lombok.jar as a java application (for example, double-click it, as a rule) to install. Also add lombok.jar to your project. Supported options: Springsource Tool Suite , JBoss Developer Studio IDEA IntelliJ The plugin developed by Michael Plushnikov adds support for most functions.

-one
source share

You need to add @Setter and @Getter annotations to the class

-4
source share

All Articles