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 @Data or @Setter.

What is deliberately not flagged

  • Constructor-bound classes: an explicit constructor with parameters, Lombok @Value, @AllArgsConstructor or @RequiredArgsConstructor, or @ConstructorBinding.

  • final fields, fields annotated with @Setter, and initialized nested objects or collections that have a getter (Spring binds into them through the getter).

  • Records, and @ConfigurationProperties placed on @Bean methods.

How to fix

Give the annotation a prefix (for example @ConfigurationProperties(prefix = "va.mobile.example")), remove properties classes that bind nothing, and add setters (or Lombok @Data/@Setter, or constructor binding) for each property.

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

Properties class Spring cannot bind
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;
    }
}

Compliant

Bindable properties class
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Data
@ConfigurationProperties(prefix = "va.mobile.example")
public class ExampleProperties {
    private int timeout;
    private String baseUrl;
}

Configuration

This rule has no configuration.