You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MethodValidationPostProcessor using multiple (custom) validators [SPR-12563] #17164
in: coreIssues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process
Currently MethodValidationPostProcessor validates using only one pre-injected validatior. Instead, it could be nice to let it use multiple validators. For example, say developers could annotate service classes with @Validated("aCustomValidatorBeanId"), and then the MethodValidationBeanPostProcessor can use the designated validator. See reference url for more.
It turns out that overriding the validator that way is a bit weird since MethodValidationPostProcessor works with JSR-303, really.
In other words, the interceptor calls Validator.forExecutables().validateParameters which would be quite awkward to extend.
I have tried a few things and none are satisfactory. Can you revisit your use case and let me know what you're trying to do exactly? In particular, pay attention that your example extends a different facade in LocalValidatorFactoryBea that's not even being called in the method validation code path.
But I want to move the validations to the service classes so that they could be called from other layers. So, I was thinking how to do that using MethodValidationPostProcessor.
Like we said already, MethodValidationPostProcessor is JSR303 validation, it won't call your validate method at all. It looks like you're looking for a variant of that BPP that would work with Spring variant, am I right?
I see. I'm sorry I could not make out what you meant by the "BPP."
So, looks like I'll have to migrate these custom validators to custom JSR-303 annotations, or call these manually in the service classes, as I can think.
in: coreIssues in core modules (aop, beans, core, context, expression)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process
Activity
spring-projects-issues commentedon Feb 24, 2015
Stéphane Nicoll commented
It turns out that overriding the validator that way is a bit weird since
MethodValidationPostProcessorworks with JSR-303, really.In other words, the interceptor calls
Validator.forExecutables().validateParameterswhich would be quite awkward to extend.I have tried a few things and none are satisfactory. Can you revisit your use case and let me know what you're trying to do exactly? In particular, pay attention that your example extends a different facade in
LocalValidatorFactoryBeathat's not even being called in the method validation code path.spring-projects-issues commentedon Feb 26, 2015
Sanjaya Kumar Patel commented
I write different custom validators, for different forms, like this one below for checking for duplicate emails in the SignupForm:
I use these in the controllers, by binding these like this:
And, my controller's handler method looks like this:
But I want to move the validations to the service classes so that they could be called from other layers. So, I was thinking how to do that using MethodValidationPostProcessor.
spring-projects-issues commentedon Feb 26, 2015
Stéphane Nicoll commented
Like we said already,
MethodValidationPostProcessoris JSR303 validation, it won't call yourvalidatemethod at all. It looks like you're looking for a variant of that BPP that would work with Spring variant, am I right?spring-projects-issues commentedon Feb 26, 2015
Sanjaya Kumar Patel commented
I see. I'm sorry I could not make out what you meant by the "BPP."
So, looks like I'll have to migrate these custom validators to custom JSR-303 annotations, or call these manually in the service classes, as I can think.
spring-projects-issues commentedon Jan 12, 2019
Bulk closing outdated, unresolved issues. Please, reopen if still relevant.