How to use Lombok in Spring

Make a note of what you did when using Lombok for Spring

Add as a library

Specify as follows in pom.xml

<dependencies>
  <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.8</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

reference

Official

Precautions for use

Instead of using @Data, use as much as you need (Addition: Because "@Getter, @Setter, @ToString, @EqualsAndHashCode, @RequiredArgsConstructor" will be given together. There is no problem if you use it after understanding it. )

When using @toString in a mutually related class, it loops infinitely, so add the exclude attribute to avoid it.

reference

Lombok usage memo It was easy to use Lombok with Spring Boot

Building a development environment (Mac)

Premise

procedure

  1. Download Lombok from the official https://projectlombok.org/download
  2. Install the downloaded file (lombok.jar) in the Eclipse installation location. Location: /Applications/Eclipse_4.7.0.app/Contents//MacOS
  3. Write the path in the Eclipse configuration file Configuration file: /Applications/Eclipse_4.7.0.app/Contents/Eclipse/eclipse.ini Description: Add the following to the bottom
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar

reference

What to do if the lombok installer doesn't work on eclipse mars / neon on mac

Question

About specifying scope in pom.xml

Provided is specified in scope. The reason is that Lombok parses the source at compile time and generates boilerplate code. The function is realized by passing it to the compiler, and it is no longer necessary after generation. For details, the following was very helpful.

reference

Lombok that no one told me

Postscript (2019/9/6)

When I tried to Maven build the project, the following error was displayed. java.lang.ClassNotFoundException: com.sun.tools.javac.code.TypeTags When I checked it, it looked like a bug and the countermeasures had already been taken, so if I specified 1.16.22, the error was resolved. It was said that it occurred in JDK10, but it also occurred in 1.8. Github:lombok Changed the version of pom.xml from 1.16.18 to 1.18.8.

Recommended Posts

How to use Lombok in Spring
How to use @Builder (Lombok)
How to use Lombok now
How to use Spring Data JDBC
How to use InjectorHolder in OpenAM
How to use CommandLineRunner in Spring Batch of Spring Boot
How to use ModelMapper (Spring boot)
How to use classes in Java?
How to set Lombok in Eclipse
How to use In-Memory Job repository in Spring Batch
How to call and use API in Java (Spring Boot)
Multilingual Locale in Java How to use Locale
How to use custom helpers in rails
How to use named volume in docker-compose.yml
How to include Spring Tool in Eclipse 4.6.3?
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How to use environment variables in RubyOnRails
Understand in 5 minutes !! How to use Docker
How to use credentials.yml.enc introduced in Rails 5.2
How to use ExpandableListView in Android Studio
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
Use Interceptor in Spring
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
How to set and use profile in annotation-based Configuration in Spring framework
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
[Rails] How to use select boxes in Ransack
How to use built-in h2db with spring boot
How to use "sign_in" in integration test (RSpec)
How to use Spring Boot session attributes (@SessionAttributes)
How to add a classpath in Spring Boot
How to use JQuery in js.erb of Rails6
How to bind to property file in Spring Boot
How to define multiple orm.xml in Spring4, JPA2.1
[Rails] How to use PostgreSQL in Vagrant environment
[Java] How to use Map
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum