See example project: https://github.com/HStoyanov-augglobal/springboot-prop-validation-issue
There is a record org.example.Props
with @ConstructorBinding
annotation whose properties i want to verify using the @MyValidProp
custom validator. This validator and the out-of-the-box @Size
validator are not being called at all. The properties themselves are validated only after the record has been constructed.
Comment From: wilkinsona
Thanks for the sample. At the moment, constructor validation with @ConfigurationProperties
isn't supported. In your example @NotBlank
works because it is propagated to a location where it can then be processed by post-construction validation. @Size
does not work because it's only present on the constructor. I'll leave this issue open as we may want to explore supporting validation during constructor binding in the future.
Comment From: likhith5697
Hi @wilkinsona, I see this enhancement is currently open and not yet assigned. I’d be interested in exploring an implementation to support validation during constructor binding for @ConfigurationProperties.
Could you please confirm if this is open for community contribution? If yes, I can start by reviewing how ValidationBindHandler and ConfigurationPropertiesBinder manage post-construction validation, and draft an approach to handle parameter-level constraints before instantiation.
Thanks!