spring-projects / spring-data-commons

Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.
https://spring.io/projects/spring-data
Apache License 2.0
778 stars 675 forks source link

`MethodValidationInterceptor` is added after `ImplementationMethodExecutionInterceptor` #3141

Open riba2101 opened 2 months ago

riba2101 commented 2 months ago

Hi,

long story short: org.springframework.aop.framework.ReflectiveMethodInvocation.proceed does not go trough the whole chain and after RepositoryFactorySupport.ImplementationMethodExecutionInterceptor the MethodValidationInterceptoris not being called. That being said, MethodValidationInterceptor should be higher up in the chain?

BR

mp911de commented 2 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

spring-projects-issues commented 2 months ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

riba2101 commented 2 months ago

hi,

sry for the wait, was a bit busy - the repo can be found here: https://github.com/riba2101/spring-data-validaition-demo

mp911de commented 2 months ago

Spring Data repository invocations are dispatched by ImplementationMethodExecutionInterceptor. However, we still set a target source and therefore, the bean post-processor inserts MethodValidationInterceptor at the end of the advisory chain.

If we do not set the target source in RepositoryFactorySupport, then the bean post-processor inserts MethodValidationInterceptor before ImplementationMethodExecutionInterceptor and so it invokes the validator.

Have you locally tried to change RepositoryFactorySupport to see whether the change would make sense to you?

riba2101 commented 2 months ago

oh, to be fair i didnt try it, a nice idea... this would be nice to document and/or make the process easier to integrate? since the MethodValidationInterceptor or rather the AOP validation is a global "feature" in the spring ecosystem, it would make sense to treat it as such?

mp911de commented 2 months ago

If such a change works for you, then we would apply that one globally so that there's no need for customizations.