-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Clarification: Spring AOP pointcuts match protected methods when CGLIB is used [SPR-15354] #19917
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
Alexander Kriegisch commented
|
Juergen Hoeller commented This has been relaxed for protected methods on CGLIB proxies a long time ago: see #6308. Unfortunately the documentation never caught up with that. The more important distinction is between calls through the proxy (on public or protected methods, consistently intercepted) and calls within the target class (never intercepted). The latter can only be addressed through weaving. |
Alexander Kriegisch commented The latter I know and it is out of scope for this question. What I wanted to know you have clarified with the link to #6308, thank you very much. So really since the old days of Spring 1.2.7 this was changed on purpose, but never documented. Wow! Now I fully agree that this is a documentation issue. |
Juergen Hoeller commented I've revised that documentation section towards the following, even mentioning that package-visible methods will be intercepted as well. Essentially, we're trying to intercept any method call on the proxy, logging a warning in the validate-class step when not possible, since otherwise such calls would end up in the uninitalized proxy instance (typically leading to NPEs when interacting with uninitialized fields etc).
|
Alexander Kriegisch opened SPR-15354 and commented
Disclaimer: I am not a Spring user, just an AspectJ expert trying to answer a StackOverflow question related to Spring AOP.
The Spring documentation in chapter 11.2.3 says:
Anyway, after I set up a little Spring Boot project and tried to use Spring AOP on a class, I saw that at least for CGLIB proxies pointcuts match protected methods. I was really surprised because the documentation says otherwise. So either the documentation is not up to date with this new "feature" or this is a regression - since which version I cannot say.
When debugging into the advice with
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
and inspectingAopContext.currentProxy()
I also see that a CGLIB proxy is created for a class which only has one protected method and for which the pointcut should not even match, thus not create a proxy.Just try something like this:
Affects: 4.3.7
Reference URL: https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-pointcuts-designators
Issue Links:
Referenced from: commits b90d3d0, 66670cf
The text was updated successfully, but these errors were encountered: