Lombok - Tutorial and Implementation

Lombok is worked to reduse boilerplate code for model/data object,e.g,it can generate getters and setters for those object automatically by using Lombok annotations.We have uased in Spring boot application .

The easiest way is to use the @Data annotation,see in bellow example:



for adding @data annotation you will get all this getters and setters.  
Step for implements lombok :-


1. To implements Lombok
1.           Add following  dependency  in pom.xml
         In  properties tag

      <lombok> 1.16.18<lombok>

      In dependencies
       
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok}</version>
            <optional>true</optional>
        </dependency>

2.Download Lombok jar from ( https://projectlombok.org/), double click on jara it will automatically install in you IDE. If it could not able to install automatically, browse and add IDE home path manually.

3. Add lambok.jar into your project

4. Add  -vmargs -javaagent:lombok.jar in STS ini file

5. Build you project

6. Remove all setter/getter toString equals and hashcode method for you entity class.

7. use @Data annotation of import lombok.Data;

No comments: