-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Validation not working when nested records are used for configuration properties #39234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report. Unfortunately, it doesn't provide enough information for us to diagnose the problem. We need to know the version of Spring Boot that you're using as well as the |
I'm using Spring Boot 3.2.1, all properties are actually null (not provided). I have similar problems with nested properties even if I use classes and not records. |
Thanks. The behaviour you have described is to be expected. With no properties to bind to an instance of @Validated
@ConfigurationProperties(prefix = "client")
record ClientProperties(@NotNull ServiceOne serviceOne) {
public record ServiceOne(@NotBlank String url, @Email String email) {
}
} With this in place, the app will fail to start due to a validation failure:
Alternatively, you can annotate it with both @Validated
@ConfigurationProperties(prefix = "client")
record ClientProperties(@DefaultValue @Valid ServiceOne serviceOne) {
public record ServiceOne(@NotBlank String url, @Email String email) {
}
} This will cause the binder to create a default
|
Thank you 🙌 |
I tried both ways how to use nested records as configuration properties. In non of them validation works. I have in the same project configuration with just one record without nesting and that works.
Examples
The text was updated successfully, but these errors were encountered: