Spring Boot lombok
Lombok
project lombok is helper for bean.
getter, setter, validation, toString, etc…
We can reduce codes.
Install Lombok
Steps
- Install Lombok for IDE
- Add dependencies
I tried STS in Windows and Mac, and Eclipse in Mac.
Both are same ways to install.
STS
Need to match pom.xml and install IDE version.
Please download or find your maven repository lombok.jar.
If you already had java in your env, please double click lombok.jar
You can see following
By default, IDEs item is not there.
Press specify location and select your IDE. In STS case, fin “STS.ini”
After finding it, press install/update.
pom.xml
Next, you can add dependency in your pom.xml
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.6</version> <scope>provided</scope> </dependency>
Example
SampleBean
@Data public class SampleBean { private Integer id; private String name; }
HelloController
@RestController public class HelloController { @RequestMapping("/greeting") public String greeting() { SampleBean sm = new SampleBean(); sm.setId(1); // Wow! return "Test"; } }
We can use setId without setter in SampleBean class.
@Data has getter/setter feature