Description
In this article (https://reflectoring.io/validate-spring-boot-configuration-parameters-at-startup/ ), it is advised to implement Validator interface in class annotated with @ConfigurationProperties
for complex checks.
This mechanism works well when class is not annotated with @ConstructorBinding.
It doesn't work if class is annotated with @ConstructorBinding
or if class is implemented as an immutable class in Spring Boot 3.0.0.
I've reproduced the issue in a Java project on this github repository for Spring Boot 2.7.7 (branch sb27
) and for Spring Boot 3.0.0 (branch master
).
In test SimpleDocumentationPropertiesTest
, validate method of class SimpleDocumentationProperties
is well called.
This class is a simple POJO with @ConfigurationProperties
annotation.
In test ConstructorBindingDocumentationPropertiesTest
, test fails because validate method of class ConstructorBindingDocumentationProperties
is not called.
This class is implemented as an immutable class with same @ConfigurationProperties
annotation and additional @ConstructorBinding
annotation (for Spring Boot 2).
Issue can also be reproduced in Kotlin projects when ConfigurationProperties classes are implemented with data classes.
I'd like to use immutable classes for all my configuration properties classes and still be able to use Validator interface for complex checks.