ConfigurationProperties Annotation Validation Rule (SL027)
Reports @ConfigurationProperties classes with no prefix, no properties, or properties Spring cannot bind.
Description
Parses each main-source class annotated with @ConfigurationProperties (every module, excluding generated code under target/) and reports problems that stop Spring from binding it as intended. The rule is advisory: every finding is INFO and never fails the build. Files that cannot be read or parsed are skipped.
What is flagged
-
The annotation has no
prefix/value, or it is blank. -
The class declares no (non-static) fields, so there is nothing to bind.
-
A non-final field has no
setXxx()method and the class does not generate setters with Lombok@Dataor@Setter.
What is deliberately not flagged
-
Constructor-bound classes: an explicit constructor with parameters, Lombok
@Value,@AllArgsConstructoror@RequiredArgsConstructor, or@ConstructorBinding. -
finalfields, fields annotated with@Setter, and initialized nested objects or collections that have a getter (Spring binds into them through the getter). -
Records, and
@ConfigurationPropertiesplaced on@Beanmethods.
Rationale
A @ConfigurationProperties class without a prefix, without properties, or with properties that cannot be bound silently leaves configuration unset at runtime.
Findings
-
INFO
-
The @ConfigurationProperties annotation has an empty or missing prefix.
-
The @ConfigurationProperties class declares no properties.
-
A property of a setter-bound @ConfigurationProperties class has no setter.
-
Noncompliant
import org.springframework.boot.context.properties.ConfigurationProperties;
// No prefix, and 'timeout' has no setter, so Spring can never bind it
@ConfigurationProperties
public class ExampleProperties {
private int timeout;
public int getTimeout() {
return timeout;
}
}