-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Document the need for compilation with -parameters when using @SpyBean and @Cacheable with a key expression that uses a parameter name #13945
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
Doing some further digging it actually appears to be deliberately ordered like that. This was introduced in gh-5837. Which was/is supposed to be the fix to work with Spring AOP, however it doesn't fix the cases in which an interceptor reads information from the method signature (like method arguments). |
Failing testcase to show the issue. When Spring AOP need method arguments to build a cache key (but probably also on other annotations that require method arguments) the AOP part will fail. Creating a Mockito mock results in the loss of the debug information needed to read the correct method parameter. issue: spring-projectsgh-13945
The debug information that's used by The debug information that's used by The problem could be avoided altogether if we could get the expression evaluation to use the method on the original object rather than from the spy's proxy but I'm not sure that's possible and it certainly wouldn't be easy to do. As things stand, I'm leaning towards a documentation change that notes that |
Is there anything in Spring Boot 1.5 preventing us from using Mockito 2? As I'm not really keen on doing a full upgrade to Spring Boot 2 just yet. |
No. As noted in the documentation you should be able to use 2.x if you wish. You'll need to override the |
Tested with both Spring Boot 1.5.14 and Spring Boot 2.0.3.
When using
@SpyBean
to investigate method calls on a bean and a method is annotated with@Cacheable
this breaks.The issue is that when using a custom key, the extension/proxy generated by
@SpyBean
apparently doesn't have the needed debug information anymore. Switching from named parameters to indexed parameters makes it work again.Exception:
Using only the
id
argument as the cache yield a slightly different exception (but the underlying cause is the same).Reproduction project has been supplied to the Spring Boot Issues repositories. See spring-attic/spring-boot-issues#79
At some further inspection this looks like an ordering issue. The
SpyPostProcessor
is aPriorityOrdered
and returns theHIGHEST_PRECEDENCE
which makes it run very early in the proces. Leading to theCacheInterceptor
seeing aOrderService#EnhanchedByMockitoCglib
.Shouldn't it be the last in line, wrapping the actual proxied instance (including the AOP) so that the spy can still record access but the regular behavior is still added (like
@Cacheable
,@Secured
etc). It appears mainly to be an issue with interceptors that also read method arguments using SpEL. Apparently the creation of the Spy first makes the actual bean a proxy which doesn't contain the needed debug information anymore.The text was updated successfully, but these errors were encountered: