-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Auto-configuration of MethodValidationPostProcessor prevents the use of @Validated on final @ConfigurationProperties classes #21454
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 providing the workaround :) |
After some brainstorming with @jhoeller, it looks like we unfortunately created an additional use-case for
Our binder looks for There are a few workarounds to be considered:
|
This comment has been minimized.
This comment has been minimized.
My recollection is that we discussed that approach, but decided against it as it would be inconsistent with how users expect to enable validation by using |
My recollection is the same as @wilkinsona |
Noting for the convenience of people googling errors, as I just spent a couple of hours rediscovering this issue (or rather something similar) and solution, at which point I immediately found this github issue. this error may manifest as
And the same workaround resolves things |
This was raised by Philipp Paland on Gitter when trying to use records for
@ConfigurationProperties
. I believe it will apply to anyfinal
@ConfigurationProperties
class that has@Validated
on it.While we don't require a proxy to perform configuration property validation,
MethodValidationPostProcessor
finds@Validated
on the bean and tries to create a proxy. When the configuration property class is final, this fails. You can work around the problem by excludingValidationAutoConfiguration
and just declaring a validator:This retains configuration property validation at the cost of method validation anywhere in the app. It would be nice if we could somehow keep both and just have the
final
@ConfigurationProperties
class excluded from method validation.The text was updated successfully, but these errors were encountered: