- • Quickstart
- • Documentation
- • Documentation DevOps
- • Spring Data
- • Spring Data MongoDB
- • Spring REST
- • Frontend
- • Multi-Module
- › IntelliJ Integration
Last updated: 2022-08-29
Using Lombok in a Spring Boot project with IntelliJ
Did you know that you can save days or weeks of development time when starting new Spring Boot apps? br With Bootify you have the right helper at your side - get a runnable prototype in minutes and focus on your business logic instead. Best practices included.
Lombok is no ordinary Java library - Lombok provides annotations which generate Java code on the fly. This can drastically shorten the source code which has to be written.
To use Lombok, first the dependency must be included in the
pom.xml. Here the annotation processor is especially important, so that Lombok can intervene directly in the compilation process. Bootify adds these dependencies automatically to the project if Lombok is enabled.
Lombok dependencies in the build.gradle
Now Lombok must be activated explicitly in the IDE. In IntelliJ you have to install a plugin for that.
Installation of the Lombok plugin in IntelliJ under "Settings → Plugins", Search for "Lombok"
Furthermore, annotation proceccing must be activated. This is already included in the dependencies, but is only used by Gradle and Maven there. IntelliJ uses its own build process, which has to be adapted separately.
Activate Annotation Processing under Settings → Build, Execution, Deployment → Compiler → Annotation Processors
The most useful helpers
Here are a few examples of these great annotations, which I always use in projects if possible.
As the names suggest, these annotations create getters and setters for all fields
With @Slf4j a static field "log" is added to the class without extra coding
@SneakyThrows is hiding exceptions from the developer
With @SneakyThrows Lombok puts a
try-catch clause around the method and wraps each potential exception into a RuntimeException. So the developer doesn't have to do this manually - in most cases a global exception handling is sufficient.
Other very practical annotations are
@Value - more information can be found in the following sources.