DEV Community

Discussion on: Spring @ConfigurationProperties annotation explained

Collapse
 
pixelstuermer profile image
Philipp Montesano • Edited

Thanks for the post.

What I like most about the feature is the possibility to avoid setters() using @ConstructorBinding, making the properties from a YAML private final and therefore immutable. And this goes hand in hand with Lombok's @AllArgsConstructor and @Getter.

For example:

@Getter
@Validated
@AllArgsConstructor
@ConstructorBinding
@ConfigurationProperties("foo")
public class FooBarProperties {

    @NotBlank
    private final String bar;

}
Enter fullscreen mode Exit fullscreen mode