How to Fix Lombok Spring Boot 3 Annotation Recognition Issues
Lombok annotations fail in Spring Boot 3 when the annotation processor runs after Spring Boot's configuration processor, preventing the generation of configuration metadata for Lombok-generated getters and setters.
When upgrading to Spring Boot 3, many developers encounter issues where Lombok annotations appear to be ignored, particularly in @ConfigurationProperties classes. According to the spring-projects/spring-boot source code, these issues typically stem from annotation processor ordering conflicts and constructor generation patterns that differ from Spring Boot's expectations.
Why Lombok Spring Boot 3 Integration Fails
The root cause lies in how spring-boot-configuration-processor generates metadata for @ConfigurationProperties beans. As documented in documentation/spring-boot-docs/src/docs/antora/modules/specification/pages/configuration-metadata/annotation-processor.adoc, the processor scans for standard Java bean getters and setters during compilation. When Lombok's annotation processor runs after Spring Boot's processor, the generated methods do not yet exist in the abstract syntax tree, causing the metadata generator to miss them entirely.
The official documentation explicitly warns:
"If you are using Lombok in your project, you need to make sure that its annotation processor runs before
spring-boot-configuration-processor."
Common Lombok Spring Boot Configuration Problems
Incorrect Annotation Processor Order
The most common issue occurs when Lombok runs after spring-boot-configuration-processor in the build configuration. The metadata processor examines the compiled abstract syntax tree; if Lombok's generated methods are missing at that point, the properties are not detected.
Maven Solution:
Ensure Lombok is listed first in the annotationProcessorPaths:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<!-- Lombok must be listed first -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</path>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Gradle Solution:
Declare Lombok before the Spring Boot processor:
dependencies {
compileOnly("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.28")
// Spring Boot configuration processor must come after Lombok
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
}
Constructor Conflicts with @ConfigurationProperties
Spring Boot 3 expects @ConfigurationProperties classes to have either a default constructor or one explicitly annotated with @ConstructorBinding. When Lombok generates constructors using @AllArgsConstructor or @RequiredArgsConstructor, it can hide the default constructor and break property binding.
Solution: Avoid constructor annotations on @ConfigurationProperties classes, or explicitly add @NoArgsConstructor alongside @ConstructorBinding when constructor injection is required.
package com.example.demo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConstructorBinding;
@Getter
@Setter
@NoArgsConstructor // explicitly keep the default constructor
@ConfigurationProperties("service")
public class ServiceProperties {
private String url;
}
IDE Annotation Processing Not Enabled
Many IDEs do not enable annotation processing by default, causing Lombok to work in command-line builds but fail in the IDE with errors like "cannot find symbol" for generated methods.
Fix: Enable "Annotation Processing" in IntelliJ IDEA (Settings → Build, Execution, Deployment → Compiler → Annotation Processors) or Eclipse project settings, and ensure Lombok is added as a provided dependency.
Incompatible Lombok Version
Spring Boot 3 requires Java 17 or higher. Lombok versions prior to 1.18.22 may not fully support newer Java features or the specific compilation flags used by Spring Boot 3.
Fix: Upgrade to Lombok 1.18.28 or later.
Verifying Your Lombok Spring Boot Configuration
To verify that Lombok-generated code is being processed correctly, check for the presence of spring-configuration-metadata.json in target/classes/META-INF (Maven) or build/classes/java/main/META-INF (Gradle). This file should contain entries for all properties defined in your @ConfigurationProperties classes, including those with Lombok-generated accessors.
If this file is missing entries for Lombok-generated properties, the annotation processors are likely running in the wrong order.
Summary
- Annotation processor order matters: Lombok must run before
spring-boot-configuration-processorto generate metadata for@ConfigurationProperties. - Avoid Lombok constructors on
@ConfigurationPropertiesclasses unless explicitly using@ConstructorBindingwith@NoArgsConstructor. - Enable IDE annotation processing to prevent compilation discrepancies between IDE and command-line builds.
- Use Lombok 1.18.22+ to ensure compatibility with Spring Boot 3's Java 17 baseline.
Frequently Asked Questions
Why are my @ConfigurationProperties not showing in application.properties autocomplete?
When Lombok runs after the Spring Boot configuration processor, the metadata generator cannot see the Lombok-generated getters and setters. This results in missing entries in spring-configuration-metadata.json, causing IDE autocomplete to fail. Ensure Lombok is declared before spring-boot-configuration-processor in your build configuration.
Can I use @Data with @ConfigurationProperties in Spring Boot 3?
Yes, but with caution. The @Data annotation generates getters, setters, and other methods that the configuration processor can recognize, provided Lombok runs first. However, @Data also generates toString(), equals(), and hashCode() which may not be desired for configuration properties. Consider using @Getter and @Setter explicitly instead.
Does Spring Boot 3 require a specific Lombok version?
Spring Boot 3 requires Java 17 or higher, and Lombok versions prior to 1.18.22 may have compatibility issues with newer Java versions or the specific compilation flags used by Spring Boot. Upgrade to Lombok 1.18.28 or later to ensure full compatibility.
How do I check if annotation processors are running in the correct order?
Check your build output for the presence of spring-configuration-metadata.json in target/classes/META-INF (Maven) or build/classes/java/main/META-INF (Gradle). If this file contains metadata for your @ConfigurationProperties classes with Lombok-generated accessors, the processors are ordered correctly. If the file is missing entries, verify that Lombok is declared before spring-boot-configuration-processor in your build configuration.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →